将 Apache Proxypass 转换为 Nginx

将 Apache Proxypass 转换为 Nginx

我发现很难理解如何为 Nginx 重写这些 apache ProxyPass 指令:

ProxyPass /api/socket ws://localhost:8082/api/socket
ProxyPassReverse /api/socket ws://localhost:8082/api/socket

ProxyPass / http://localhost:8082/
ProxyPassReverse / http://localhost:8082/

到目前为止我已经尝试过:

proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_redirect http://mydomain:8082/ https://mydomain/alias/;
proxy_redirect ws://mydomain:8082/api/socket ws://mydomain/alias/api/socket;
proxy_pass http://localhost:8082/;

但没有成功。

答案1

您应该添加以下选项

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

相关内容