nginx配置文件和相关命令,nginx配置文件命令


[root@ansible ~]# whereis nginx        #查看nginx位置
nginx: /usr/local/nginx
[root@ansible ~]# cd /usr/local/nginx
[root@ansible nginx]# ls
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  ssl  uwsgi_temp
conf目录为配置文件目录,html存放网页文件,logs存放日志文件,sbin存放二进制nginx程序,ssl存放https密钥文件

[root@ansible nginx]# cat conf/nginx.conf | grep -v '^$'  #查看配置文件,过滤掉空行
#user  nobody; #运行用户
worker_processes  1; #启动进程,通常和CPU数相等
#全局错误日志
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;  #pid文件

#工作模式及连接数上限
events {
    worker_connections  1024;   #单个后台worker_process进程的最大并发连接数
}
http {
    include       mime.types;  #设定mime类型,类型由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 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
    #对于普通应用,必须设为 on,
    #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
    #以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;   #连接超时时间
    keepalive_timeout  65;
    #gzip  on;   #开启gzip压缩
    #虚拟主机配置
    server {
        listen       80;  侦听80端口
        server_name  localhost;  #虚拟主机名称
        #charset koi8-r;
        #access_log  logs/host.access.log  main;  虚拟主机的访问日志
        location / {
            root   html; #虚拟主机根目录
            index  index.html index.htm; #默认首页索引文件
        }

    #查看nginx状态的模块
    location /nginx_status {
    stub_status on;
        access_log off;
        allow all;允许的ip
        #deny all;拒绝的ip
}
        #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;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #

        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    #HTTPS server
    #
    #https虚拟主机配置
    server {
        listen       443 ssl;
        server_name  192.168.29.9;
        证书和密钥存放位置,自定义的
        ssl_certificate      /usr/local/nginx/ssl/nginx.crt; 
        ssl_certificate_key  /usr/local/nginx/ssl/nginx.key;
    #   keepalive_timeout 70;
    #   server_tokens off;
    #   fastcgi_param   HTTPS       on;
    #   fastcgi_param   HTTPS_SCHEME    https;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
        location / {
            root   html;
            index  index.html index.htm;
         }
     }
}

nginx相关命令
验证配置是否正确: nginx -t
[root@ansible nginx]# /usr/local/nginx/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 -V
[root@ansible nginx]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module

启动Nginx:nginx或nginx -c
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #若不用-c指定配置文件,则以默认配置启动

快速停止或关闭Nginx:nginx -s stop
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -s stop

正常停止或关闭Nginx:nginx -s quit
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -s quit

配置文件修改重装载命令:nginx -s reload
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -s reload

重新打开日志文件:nginx -s reopen
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -s reopen

打开帮助信息:nginx -h
[root@ansible sbin]# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.8.1
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file

相关内容

    暂无相关文章