Windows下配置Nginx配置多個VUE前端項目


  1. VUE 打包好前端項目
  2. 下載Nginx   http://nginx.org/en/download.html

 

 

 

 使用穩定版,下載好后解壓得到如下目錄

將打包好的前端項目copy到html文件夾中

 

 

 

其中最主要的配置文件nginx.conf在conf文件夾中

  • 原配置
 1     server {
 2         listen       80;  #端口
 3         server_name  localhost;  #IP
 4 
 5         #charset koi8-r;
 6 
 7         #access_log  logs/host.access.log  main;
 8 
 9         location / {
10             root   html; #web路徑
11             index  index.html index.htm;
12         }
13 
14         #error_page  404              /404.html;
15 
16         # redirect server error pages to the static page /50x.html
17         #
18         error_page   500 502 503 504  /50x.html;
19         location = /50x.html {
20             root   html;
21         }
22 
23         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
24         #
25         #location ~ \.php$ {
26         #    proxy_pass   http://127.0.0.1;
27         #}
28 
29         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
30         #
31         #location ~ \.php$ {
32         #    root           html;
33         #    fastcgi_pass   127.0.0.1:9000;
34         #    fastcgi_index  index.php;
35         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
36         #    include        fastcgi_params;
37         #}
38 
39         # deny access to .htaccess files, if Apache's document root
40         # concurs with nginx's one
41         #
42         #location ~ /\.ht {
43         #    deny  all;
44         #}
45     }
  • 修改后的配置
     root   D:/nginx-1.20.2/html;
        location / {
            try_files $uri $uri/ @router;
            index  index.html index.htm;
        }
        location @router{
                rewrite ^.*$ /index.html last;
            }

還有一種方法配置多個server(不推薦)

啟動Nginx

使用cmd命令

  • start nginx 啟動nginx
  • nginx -s reload  :修改配置后重新加載生效

關閉nginx:

  • nginx -s stop  :快速停止nginx
  • nginx -s quit  :完整有序的停止nginx

啟動后在瀏覽器運行http://localhost:8088/dist1

 


免責聲明!

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



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