nginx解决前端跨域
1、安装好nginx后,进入/usr/local/etc/nginx/nginx.conf
2、修改配置如下:
server {
listen 9090; // 监听端口
location /ms { // http://192.168.110.251:9090/ms/line/lineList => http://dev.op110.com.cn/ms/line/lineList
#root html;
#index index.html index.htm;
proxy_pass http://dev.op110.com.cn;
# proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 100m;
proxy_connect_timeout 5;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_intercept_errors on;
}
location / {
proxy_pass http://192.168.110.251:8080; // 本地域名和端口号
# proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
client_max_body_size 100m;
proxy_connect_timeout 5;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_intercept_errors on;
}
}
网友评论