nginx连接后面的凤凰websocket拒绝了

时间:2017-04-29 08:06:22

标签: apache nginx channel phoenix

在nginx之前,也无法使用apache反向代理在nginx后面使用phoenix channel。

网站没问题,但无法建立套接字连接。套接字在开发模式下可以,一切正常。凤凰城没有授权设置

defp authorized?(_payload) do
    true
 end

错误消息

2017/04/29 09:40:50 [error] 10451#10451: failed (111: Connection refused) 
while connecting to upsteam, client: 192.168.0.10, 
server: somehost.com, 
request: "GET /socket/websocket?token=undefined&vsn=1.0.0 HTTP/1.1",
upstream:"http://phoenix3/socket/websocket?token=undefined&vsn=1.0.0", 
host: "somehost.com"

按照此主题的指南进行操作是我提出的设置

在user_socket.ex

transport :websocket, Phoenix.Transports.WebSocket, check_origin: ["//somehost.com"]
端点

中的

config :myapp, MyApp.Endpoint,                                               
  http: [port: {:system, "PORT"}],                                                   
  url: [host: "somehost.com", port: 80],                               
  cache_static_manifest: "priv/static/manifest.json"  

在nginx中

nb X-Real-IP或X-Cluster-Client-IP都失败

upstream phoenix3 {                                                                  
   server localhost:4020 max_fails=5 fail_timeout=60s;                           
}                                                                                    
map $http_upgrade $connection_upgrade {                                             
 default upgrade;                                                            
 '' close;                                                                   
}                                                                                    
server {                                                                             
  listen 80;                                                                   
  listen [::]:80;                                                              
  server_name somehost.com;                                      

   access_log /home/user1/appdir/log/access.log;                             
   error_log  /home/user1/appdir/log/error.log;                              
   location / {                                                                 

   # Proxy Headers                                                              
   proxy_set_header X-Real-Ip $remote_addr;                                    
   # proxy_set_header X-Cluster-Client-Ip $remote_addr;                         
   proxy_http_version 1.1;                                                     
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                
   proxy_set_header Host $http_host;                                           


 # The Important Websocket Bits!                                             
 proxy_set_header Upgrade $http_upgrade;                                     
 proxy_set_header Connection $connection_upgrade;                            

 proxy_pass http://phoenix3;                                                 
 proxy_redirect off;                                                         

 }                                                                            
apache中的

(获取真实世界的连接)

<VirtualHost *:80>      
  ServerName somehost.com
   ProxyPreserveHost On                                                             
   ProxyRequests off                                                                
   ProxyPass / http://192.168.0.26/                                                 
   ProxyPassReverse / http://192.168.0.26/
</VirtualHost>                                           

1 个答案:

答案 0 :(得分:1)

问题是apache配置。 nginx配置没问题,凤凰配置也没问题

在apache虚拟主机中,需要添加

ProxyPass /socket/ ws://192.168.0.26/socket/                                     
ProxyPassReverse /socket/ ws://192.168.0.26/socket/     

在第一个块之前,然后添加一个额外的apache模块

a2enmod proxy_wstunnel
service apache2 restart