nginx https反向代理设置
参考配置: (场景:为了解决chrome80+ Same-site-default-value,跨站无法传递cookie问题)
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
error_log /var/log/nginx/http.log info;
access_log /var/log/nginx/access.log;
upstream omc {
server bctestlabomc.cloudapp.net:8081;
}
upstream boss {
server baicellstest01.cloudapp.net:7080;
}
server {
listen 8081 ssl;
ssl_certificate /usr/local/ssl/nginx/1_baicells.cloudapp.net_bundle.crt; #https证书
ssl_certificate_key /usr/local/ssl/nginx/2_baicells.cloudapp.net.key; #https密钥
location / {
proxy_pass http://omc;
}
access_log /var/log/nginx/server.log;
}
server {
listen 8082 ssl;
ssl_certificate /usr/local/ssl/nginx/1_baicells.cloudapp.net_bundle.crt;
ssl_certificate_key /usr/local/ssl/nginx/2_baicells.cloudapp.net.key;
location / {
proxy_pass http://boss;
}
}
}
附:
Nginx代理跨域
CORS使用Nginx配置。如下,对于非简单请求,浏览器总共会发两次请求,第一次是预检请求OPTIONS。
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
if ($request_method = 'OPTIONS') {
return 204;
}
}