Nginx 配置示例
puma应用
upstream myapp {
server tcp://0.0.0.0:3001;
}
server {
listen 80;
server_name www.one.work;
location /cable {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
root /opt/srv/xxxx/current/public;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://myapp;
}
}
请求转发
server {
listen 80;
server_name wechat.one.work;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://xx.xx.xxx.xx:20000; # 外网IP
}
}
websocket
location /cable {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}