nginx配置多tomcat实例
参考路径:https://www.cnblogs.com/windysai/p/6808476.html
引申问题:
nginx解决跨域问题:
#对于前端的配置
server {
listen 80;
server_name localhost zengchang-domain-front.com;
access_log logs/zengchang-domain-front.access.log;
location / {
root html;
index index.html index.htm;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost:8090;
}
}
#对于后端的配置
server {
listen 80;
server_name localhost zengchang-domain-back.com;
access_log logs/zengchang-domain-back.access.log;
location / {
root html;
index index.html index.htm;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost:8080;
# 处理跨域请求
add_header 'Access-Control-Allow-Origin' '*';
}
}
前端调用的时候注意:
后端可以不再加header了: