当前位置:   首页安装配置后端分离:Nginx实现前后端分离

后端分离:Nginx实现前后端分离

发布日期:2021-12-30 14:27 | 文章来源:CSDN

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

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部