Nginx common configuration

Time:2019-12-9

Nginx operation

Location nginx

There are multiple nginx on the server, locating the configuration file of the currently running nginx

PS - EF | grep nginx ා view the location of the currently running nginx
#1. Check the PID of nginx. Take the commonly used port 80 as an example:
netstat -anop | grep 0.0.0.0:80
#2. Query the currently running nginx path through the corresponding process ID (for example: 4562):
 ll  /proc/4562/exe
#3. After obtaining the execution path of nginx, use the - t parameter to obtain the corresponding configuration file path of the process
/usr/local/nginx/sbin/nginx -t
#Output the following
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 command

Linux nginx start restart shutdown command:

The following commands should be run in the response directory or in the full path
Home / Odin / nginx / SBIN / nginx – s reload – reloads the configuration and takes effect

#Start the nginx to be started under the SBIN directory
  . / nginx - s reload - reloads the configuration and takes effect
  #The start action - C parameter specifies the nginx configuration file path to load
  ./nginx -c /usr/local/nginx/conf/nginx.conf
#Reopen log file
  ./nginx -s reopen
#Test whether nginx configuration file is correct
  ./nginx -t -c /path/to/nginx.conf
Nginx stopped
  Nginx - s stop
  Quit? Stop nginx completely and orderly
#Other ways to stop nginx: find the way to send signals to the process
  #Step 1: query the nginx main process number
  ps -ef | grep nginx
  #Step 2: send signal
  Kill - quit 16391 - stop nginx calmly:
  Kill - term 16391 - fast stop nginx:
  Kill - 9 16391 - force stop nginx:

Attach profile

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    
    #Multi port configuration under Vhost folder
    include       ./vhost/*.conf;

    sendfile        on;     

    server {
        listen       8088;
        server_name  localhost;
        
        

        location / {     
            Root D: \ wuworkspace \ Wu project \ Wu vueproject \ mysgmpro \ feature ﹣ V2 ﹣ 9 ﹣ dist; ﹣ file directory         
            Try ﹐ files $URI $URI / @ router; ﹐ you need to point to the following @ router, otherwise the route of Vue will be refreshed in nginx and 404 will appear
            Index index.html; default start page
        }
        
        #Corresponding to the above @ router, the main reason is that the route resource is not a real path, so the specific file cannot be found
        #Therefore, you need to rewrite it to index.html, and then hand it to the router to process the request resource
        location @router {
          rewrite ^.*$ /index.html last;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }        
        
        #location ~ /\.
        #{
        #    deny all;
        #}    
    }    
}