關於配置安全網路套接字有什麼想法嗎?我在 C# 中使用 System.Net.WebSocket 作為伺服器。我想為此設定 nginx。 WebSocket 會監聽https://本地主機:9000。 nginx 設定檔中需要進行哪些設定。
答案1
透過閱讀你的問題,我猜你是在要求 https 上游代理的 nginx 虛擬主機設定範例。
這是這樣一個配置範例:
server {
listen 443;
listen [::]:443;
server_name www.example.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass https://localhost:9000;
proxy_ssl_certificate /etc/nginx/client.pem;
proxy_ssl_certificate_key /etc/nginx/client.key
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_ciphers HIGH:!aNULL:!MD5;
proxy_ssl_trusted_certificate /etc/nginx/trusted_ca_cert.crt;
proxy_ssl_verify on;
proxy_ssl_verify_depth 2;
proxy_ssl_session_reuse on;
}
}
也許您也希望有 http -> https 的重定向:
server {
listen 80;
listen [::]:80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
更多請參閱NGINX:保護上游伺服器的 http 流量和