本文主要和大家分享Nginx設定前後端分離實例程式碼,為了幫助大家更好的掌握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 { include mime.types; default_type application/octet-stream; #sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; proxy_set_header Cookie $http_cookie; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; gzip on; sendfile on; server { listen 8100; server_name localhost; location =/ { root /Users/abee/WebstormProjects/Angular/dist; index index.html index.htm; try_files $uri $uri/ /index.html =404; } location ~* \.(js|css|htm|html|gif|jpg|jpeg|png|bmp)$ { root /Users/abee/WebstormProjects/Angular/dist; } location / { proxy_pass http://localhost:8200/; } } }
如果有多個server端location
可使用另一種設定
location /server1/ { proxy_pass http://localhost:8300/; }
只作測試參考。
相關推薦:
#以上是Nginx設定前後端分離實例程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!