nginx子路徑訪問前端Vue打包項目

1.nginx.conf配置

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        # 引入外部模塊配置文件
        include /usr/local/nginx/conf/modules/*.conf;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

2.nginx.conf同級目錄創(chuàng)建modules文件夾,創(chuàng)建[xx模塊名稱].conf

location /[xx路徑]{
    alias /home/www/[xx文件夾]; # 子路徑要用alias,不能用root
    try_files $uri $uri/ index.html =404;
    index  index.html index.htm;
}
# 代理
location /api {
      proxy_pass http://127.0.0.1:8081;
      proxy_set_header Host $http_host; #后臺可以獲取到完整的ip+端口號
      proxy_set_header X-Real-IP $remote_addr; #后臺可以獲取到用戶訪問的真實ip地址
}
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容