Separate front and rear ends to forward Nginx

Front and rear ends a front end as a web Nginx separation vessel, typically need to access the backend interface need path forwarding, direct access to the API will cause a rear end cross-domain problem, the following configuration file

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
         }

         location ^~ /app/ {
          
            proxy_pass  http://localhost:8081/;
         }

Which port 80, access to the root path HTTP: // localhost / nginx container itself was content, such as access to HTTP: // localhost / App / cross-domain will be forwarded to http: // localhost: 8081 / directory, namely access

http://localhost/app/api/test 实为 http://localhost:8081/api/test 。

Guess you like

Origin www.cnblogs.com/wangpeili/p/12501686.html