Fork me on GitHub

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

 

posted @ 2021-12-23 15:51  我是来揍你的  阅读(1132)  评论(0编辑  收藏  举报