Nginx设置

一、Nginx

  • 稳定性高
  • 系统资源消耗低
  • 对HTTP并发连接的处理能力高

Nginx配置

首先将软件包从Windows上挂载到Linux上进行压缩

1、解压文件

[root@localhost abc]# tar zxvf nginx-1.12.2.tar.gz -C /opt/   //解压到/opt里

2、安装依赖包

[root@localhost abc]# yum install gcc gcc-c++ pcre-devel zlib-devel -y

3、创建Nginx的用户

[root@localhost abc]# useradd -M -s /sbin/nologin nginx

4、进入到nginx-1.12.0路径里开始编译

./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module

5、保持不变,进行make && make install

[root@localhost nginx-1.12.2]# make
[root@localhost nginx-1.12.2]# make install

6、为了方便管理文件,创建一个软连接

[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

7、测试nginx

[root@localhost sbin]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx,并关闭防火墙和增强性安全功能

nginx -t              //检查
nginx	              //启动
killall -1 nginx      //重启
killall -3 nginx      //停止
[root@localhost sbin]# systemctl stop firewalld.service 
[root@localhost sbin]# setenforce 0

8、安装elinks,后续需要使用其检测

[root@localhost sbin]# yum install elinks -y

9、在网页上访问Nginx网站
在这里插入图片描述
10、为了方便控制Nginx,制作脚本进行控制

#!/bin/bash
# chkconfig: - 99 20
# description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
   start)
   $PROG
   ;;
   stop)
   kill -s QUIT $(cat $PIDF)
   ;;
   restart)
   $0 stop
   $0 start
   ;;
   reload)
   kill -s HUP $(cat $PIDF)
   ;;
   *)
       echo "Usage: $0 {start|stop|restart|reload}"
       exit 1
esac
exit 0

11、基于执行权限,并添加到服务列表中

[root@localhost init.d]# chmod +x nginx 
[root@localhost init.d]# chkconfig --add nginx 

12、通过脚本就可以直接开启和关闭

[root@localhost init.d]# service nginx stop    //关闭Nginx
[root@localhost init.d]# netstat -ntap | grep 80     //查看Nginx端口是否开启
[root@localhost init.d]# service nginx start      //开启Nginx
[root@localhost init.d]# netstat -ntap | grep 80   //查看端口
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      57745/nginx: master 
[root@localhost init.d]# 

配置nginx.conf

全局配置

#user  nobody;   //运行用户
worker_processes  1;   //工作运行数量

#error_log  logs/error.log;   //错误日志文件的位置
#error_log  logs/error.log  notice;  
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;  //PID文件位置

I/O事件配置

events {
    worker_connections  1024;  //每个进程处理1024个连接
}

HTTP配置

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;   //访问日志位置

    sendfile        on;                  //支持文件发送(下载)
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;              //连接保持超时
    #gzip  on;

    server {   //web服务器的监听配置
        listen       80;               //监听端口
        server_name  localhost;        //域名

        #charset utf-8;         //网页的默认字符集  

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        root   html;
        }

访问状态统计


    #gzip  on;

    server {
        listen       80;
        server_name  www.kgc.com;   //监听地址

        #charset utf-8;        

        access_log  logs/host.access.log;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
          stub_status on;
          access_log off;
        }

修改完之后重新启动

[root@localhost conf]# service nginx stop
[root@localhost conf]# service nginx start

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值