反向代理http配置
server { listen 80; server_name xxx.xxx.xxx; location / { proxy_pass http://127.0.0.1:8080; } }
反向代理websocket配置
nginx.conf 的http段内增加如下代码:
map $http_upgrade $connection_upgrade { default upgrade; '' close; }
在对应的server段内增加如下代码:
location /dctrl/ws { proxy_pass http://10.217.20.102:8093; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; 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 $connection_upgrade; proxy_set_header Origin ""; }
配置http访问自动跳转到https
server { listen 80; server_name www.域名.com; rewrite ^(.*) https://$server_name$1 permanent; } server { listen 443; server_name www.域名.com; root /home/www; ssl on; ssl_certificate /etc/nginx/certs/server.crt; ssl_certificate_key /etc/nginx/certs/server.key; }