- 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