Windows下配置Nginx配置多个VUE前端项目
- VUE 打包好前端项目
- 下载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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)