Nginx实现前后端分离

Naomi ·
更新时间:2024-11-11
· 819 次阅读

#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实现前后端分离的全部内容,感谢你对软件开发网的支持。

您可能感兴趣的文章:基于NodeJS的前后端分离的思考与实践(六)Nginx + Node.js + Java 的软件栈部署实践nginx+vue.js实现前后端分离的示例代码详解基于Vue,Nginx的前后端不分离部署教程部署前后端分离式nginx配置的完整步骤



前后端分离 Nginx

需要 登录 后方可回复, 如果你还没有账号请 注册新账号