1、 HTTP 请求
server {
listen 80;
server_name www.xxxxxxxx.com;
location / {
proxy_pass http://127.0.0.1:8089;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Forwarded $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
root /home/project/WebContent;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/project/WebContent;
}
}
2、HTTPS
3、前后端分离(nginx跨域问题)
server {
listen 80;
server_name localhost;
location ~* \.htm$ { # 我的服务端接口格式是: /**/*.htm .
proxy_pass http://127.0.0.1:8221;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Forwarded $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
}
location / { # 非 .htm,应该就是前端的了, 走通过匹配
root /home/system_web;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/system_web;
}
}
注意的是,前端发送请求时,url接口不需要再带服务端的端口号:
http://xxx.x.x.xxx:8221/login.htm ==> http://xxx.x.x.xxx/login.htm
网友评论