nginx部署vue项目
-
vue打包生成dist文件夹
-
nginx安装见博客https://editor.csdn.net/md/?articleId=122439899
-
如果执行安装nginx的时候报错:the HTTP rewrite module requires the PCRE library.
请执行:
yum -y install pcre-devel
-
如果执行安装nginx的时候报错:the HTTP gzip module requires the zlib library
请执行:
yum -y install zlib-devel
-
-
修改nginx配置文件增加一下内容
server {
listen 8899;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /opt/nginx/html/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /prod-api/ {
rewrite ^/prod-api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:9999;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
-
启动nginx
./nginx