打包后程序上线到Linux ,可以选择tomcat,也可以选择nginx。
输入rz命令使用Linux文件上传,看是否已经安装了lrzsz,如果没有安装,就执行安装命令。
yum -y install lrzsz
nginx配置文件 /etc/nginx/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8099;
server_name localhost;
location / {
root D:dist;
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.3.99:8081/;
proxy_read_timeout 3600;
}
location /dev-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.3.99:8081/;
proxy_read_timeout 3600;
}
location /stage-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.3.99:8081/;
proxy_read_timeout 3600;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
root /xxx/dist; 上线程序路径
/dev-api/ 开发包跨域
/stage-api/ 测试包跨域
/prod-api/ 上线包跨域
如果需要启动多个项目只需要再加一个server{配置}就可以
proxy_read_timeout 3600; 超时时间设置成1小时
//nginx刷新报404错误 添加配置解决
location / { try_files $uri $uri/ @router; } location @router { rewrite ^.*$ /index.html last; }