nginx安裝、部署前端、請求轉發


1、安裝可以參考這篇博客

2、部署前端程序

 location /
         {
            root   /var/www/dist;  # 前端程序所在路徑
            index  index.html index.htm;  # 指定請求的首頁html
        }

3、轉發,請關注着色部分

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #部署前端的程序
        location /
         {
            root   /var/www/dist;
            index  index.html index.htm;
        }

        #轉發使用 
        location /docs {
        #將http://132.232.44.72:8080/docs/訪問地址轉發到  http://132.232.44.72:80/docs/這個地址       
                proxy_pass http://132.232.44.72:8080/docs/;
 }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

4、開啟多個端口服務

 server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #部署前端的程序
        location /
         {
            root   /var/www/dist;
            index  index.html index.htm;
        }

        #轉發使用 
        location /docs {
        #將http://132.232.44.72:8080/docs/訪問地址轉發到  http://132.232.44.72:80/docs/這個地址       
                proxy_pass http://132.232.44.72:8080/docs/;
         }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}
###開啟 8000端口 server { listen
8000; server_name localhost; location /examples { proxy_pass http://localhost:8080/examples/; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }

完畢


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM