我正在尝试在我的 osx 开发机器上配置 nginx(通过 macports 安装)。我正尝试将 localhost:12346/trade 反向代理到远程机器上 /trade 的端口 12346 上可用的 websocket 连接。
我正在使用以下 nginx.conf 文件。注释掉 SSL SECTION 后,它可以正常工作,但取消注释后,nginx 将无法正常启动。我根据此处和其他网站的其他问题和答案模拟了 conf 文件。我尝试了 20 种不同的方法,但只要取消注释任何与 SSL 相关的行,nginx 就不会启动。
worker_processes 1;
events {
worker_connections 20;
}
error_log /opt/local/etc/nginx/debug.log debug;
http {
include mime.types;
default_type application/octet-stream;
#
# Some default configuration.
#
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#
# A list with load balancing backends hashed on IP for sticky load balancing.
#
upstream backend {
# ip_hash;
server 123.456.78.90:12346;
}
server {
listen 12346; # ssl used here when un-commented
server_name localhost;
# SSL SECTION
# ssl on;
# ssl_certificate /opt/local/etc/nginx/server.crt;
# ssl_certificate_key /opt/local/etc/nginx/server.key;
# ssl_session_cache builtin:1000 shared:SSL:10m;
#
# ssl_session_timeout 5m;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
# ssl_prefer_server_ciphers on;
# END SSL SECTION
#
# Proxy settings
#
location /trade {
proxy_pass http://backend/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket specific
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
#
# Specific for comet or long running HTTP requests, don't buffer up the
# response from origin servers but send them directly to the client.
#
proxy_buffering off;
#
# Bump the timeout's so someting sensible so our connections don't
# disconnect automatically. We've set it to 12 hours.
#
proxy_connect_timeout 43200000;
proxy_read_timeout 43200000;
proxy_send_timeout 43200000;
}
}
}
有人能发现我做错什么吗?
答案1
搞定了。使用 Macports 时,您必须使用sudo port install nginx +ssl
Stupid 明确安装支持 SSL 的 nginx,我知道 - 为什么您要在没有 SSL 的情况下安装它,为什么您的标志以 + 开头...