Nginx系统学习笔记(1)Say Hello
最近项目一直是用Ngix来部署前后端代码,接下来准备系统的学习Nginx,将学到的知识记录下,忘记时可以随时查看。
Nginx的安装就不再详细记录,直接到官网http://nginx.org/en/download.html 下载,按网上安装部署即可。
英文文档:http://nginx.org/en/docs/
中文文档:https://www.nginx.cn/doc/
另外在https://www.nginx.com/ 也有很多文档及相关资讯,有兴趣的朋友可以多去逛逛。
顺便附带个我们项目开发、测试环境中Nginx的配置文件结构,仅供参考:
#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; events { worker_connections 1024; } http { client_max_body_size 50m; server_tokens off; 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; # test port start server { listen 6061; server_name localhost; location / { root e:/nginx-1.14.2/html/xxxTest/PC; index index.html index.htm; try_files $uri $uri/ /index.html; } location @router { rewrite ^.*$ /index.html last; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ^~ /api/ { # rewrite ^.+apis/?(.*)$ /$1 break; include uwsgi_params; proxy_pass http://xxx/api/; } } # another virtual host using mix of IP-, name-, and port-based configuration # server { listen 6062; server_name localhost; location / { root e:/nginx-1.14.2/html/xxxTest/Mobile; index index.html index.htm; try_files $uri $uri/ /index.html; } location @router { rewrite ^.*$ /index.html last; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ^~ /api/ { # rewrite ^.+apis/?(.*)$ /$1 break; include uwsgi_params; proxy_pass http://xxx/api/; } }
# test port end server { listen 6099; server_name localhost; location / { root e:/Log_xxx; index index.html index.htm; autoindex on; } } # Dev port start server { listen 6051; server_name localhost; location / { root e:/nginx-1.14.2/html/xxxDev/PC; index index.html index.htm; try_files $uri $uri/ /index.html; } location @router { rewrite ^.*$ /index.html last; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ^~ /api/ { include uwsgi_params; proxy_pass http://xxx/api/; } } server { listen 6052; server_name localhost; location / { root e:/nginx-1.14.2/html/xxxDev/Mobile; index index.html index.htm; try_files $uri $uri/ /index.html; } location @router { rewrite ^.*$ /index.html last; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ^~ /api/ { include uwsgi_params; proxy_pass http://xxx/api/; } } # Dev port end # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # 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; # } #} }