Nginx之常用操作

  1) 将XXX.com 重定向到 www.XXX.com 

server {
        client_max_body_size 20m;
        listen       80;
        server_name  www.xxx.com xxx.com;
        access_log  /data/varlog/nginx/xxx.log  main;
        error_log /data/varlog/nginx/xxx_err.log error;
        root           /data/wwwroot/web/xxx/public;
           index  index.php index.html index.htm;
        if ($http_host = xxx.com) {
            rewrite (.*) http://www.xxx.com;
        }
        location / {
         try_files $uri $uri/  /index.php?_url=$uri&$args;    
        }
    gzip on;

        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }

        location ~ .php$ {
        try_files $uri =404;

            fastcgi_pass   127.0.0.1:9725;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        /usr/local/openresty/nginx/conf/fastcgi_params;
        }

        location ~ /.ht {
           deny  all;
        }
        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            access_log off;
        }
    }

  2)重启NGINX

sudo nginx -c /etc/conf/nginx.conf -t ; 验证NGINX配置
sudo nginx -c /etc/conf/nginx.conf -s reload  ;重启NGINX服务

  3)NGINX常用命令

nginx -h 查看帮助
nginx version: openresty/1.11.2.5
Usage: nginx [-?hvVtTq] [-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
  -T            : test configuration, dump it 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/openresty/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
原文地址:https://www.cnblogs.com/xingxia/p/nginx_operations.html