当前位置:Gxlcms > JavaScript > Nginx设置前后端分离实例代码

Nginx设置前后端分离实例代码

时间:2021-07-01 10:21:17 帮助过:15人阅读

本文主要和大家分享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/;
        }

仅作测试参考。

相关推荐:

有关前后端分离与实践的nodejs中间层服务的知识

关于前后端分离的实例教程

javascript - 网站前后端分离问题,API编写

以上就是Nginx设置前后端分离实例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行