Home > Web Front-end > JS Tutorial > Nginx setup front-end and back-end separation example code

Nginx setup front-end and back-end separation example code

小云云
Release: 2018-02-08 15:16:04
Original
2312 people have browsed it

This article mainly shares with you the example code of Nginx setting up front-end and back-end separation. In order to help you better master Nginx setting up front-end and back-end separation, the code shared in this article is very detailed. I hope it can help everyone.

#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/;
        }
      
        
    }
}
Copy after login

If there are multiple serverslocationYou can use another configuration

 location /server1/ {
            proxy_pass http://localhost:8300/;
        }
Copy after login

For testing reference only.

Related recommendations:

Knowledge about front-end and back-end separation and practical nodejs middle-tier services

Example tutorial on front-end and back-end separation

javascript - Website front-end and back-end separation issues, API writing

The above is the detailed content of Nginx setup front-end and back-end separation example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template