1. 程式人生 > 實用技巧 >Nginx系統學習筆記(1)Say Hello

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; # } #} }