Install nginx
$yum install nginx $yum install nginx # nginx $nginx -v $yum install nginx # nginx $nginx -vCopy the code
Location of nginx related files
/usr/sbin/nginx: main program /etc/nginx: stores configuration files. /usr/share/nginx: stores static files. /var/log/nginx: stores logsCopy the code
Common commands
Nginx -s reopen # restart nginx -s reopen # stop nginx stop nginxCopy the code
Nginx configuration file
File location: /etc/nginx/nginx.conf
The initial content of the nginx.conf file is demo content. Modify the file as required.
#For more information on configuration, see: # * Official English Documentation: http: //nginx.org/en/docs/ # * Official Russian Documentation: HTTP: //nginx.org/ru/docs/ # user nginx; Worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; #Load dynamic modules. See /usr/share/nginx/README.dynamic. include/usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; Gzip on; gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss application/xhtml+xml application/x-font-ttf application/x-font-opentype image/svg+xml image/x-icon; }Copy the code
Above is the main configuration file, take out your server configuration section individually, here in the/etc/nginx/conf. D/test. The conf file, the test. The conf is your new server configuration files (name watch).
Include /etc/nginx/conf.d/*.conf
Nginx server configuration
File location: / etc/nginx/conf. D/test. Conf
Server {# port number listen 80; Server_name 47.102.195.218; index index.html index.htm; access_log /var/log/nginx/freedom01.access.log main; error_log /var/log/nginx/freedom01.error.log warn; The location / {# corresponding static resource directory root/data/WWW/test/freedom01 / dist. index index.html index.htm; if (! -e $request_filename) { rewrite ^ /(.*) /index.html last; break; Location/API {limit_except GET POST {deny all; } proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # begin with/API forward requests to the server port 3000 / API proxy_pass http://127.0.0.1:3000/api; proxy_redirect off; }}}Copy the code
Common error
1. Nginx: [error] invalid PID number is reported after the nginx -s reload command is executed
Solution: Run nginx -c /etc/nginx/nginx.conf
If you haven’t solved, reference blog.csdn.net/PT1993/arti…
2. 403 Forbidden is displayed on nginx
Solution:
Solution 1: The user in the nginx.conf file is inconsistent with the startup user.
Solution 2: Nginx does not have the operation permission on the Web directory. Change the read/write permission on the web directory and restart nginx.
chmod -rw 777