apache - Apache2 配置到 Nginx 配置?
问题描述
我现在有 2 个端口在我的服务器上运行。
- 即主应用程序端口 5455
- 套接字端口 8433
我们正在将此 apache 设置迁移到 Nginx。在 Apache 中,我们有 2 个 conf 文件,1 个用于应用程序服务器,1 个用于套接字
我已经能够正确移动应用程序服务器但无法使套接字工作
<VirtualHost _default_:8443>
ServerAdmin admin@abc.tech
ServerName api.abc.tech
DocumentRoot /var/www/api.abc.tech/socket
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:8000/$1 [P,L]
ProxyPass /socket.io/ http://127.0.0.1:8000/socket.io/
ProxyPassReverse /socket.io/ http://127.0.0.1:8000/socket.io/
SSLCertificateFile /etc/apache2/sites-available/api.abc.tech.crt
SSLCertificateKeyFile /etc/apache2/sites-available/api.abc.tech.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
我当前的 Nginx 文件如下
server {
listen 8443;
server_name _;
location / {
proxy_pass http://localhost:8443;
}
}
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
ssl_certificate /etc/letsencrypt/live/api.abc.tech/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.abc.tech/privkey.pem;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name api.abc.tech;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5455;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 200;
}
}
location ^~ /.well-known/acme-challenge/ {
allow all;
}
}
因此,当应用程序遇到以下路线时
https://api.abc.tech:8443/socket.io/?EIO=3&transport=polling&t=MvOh2
它返回低于错误
Referrer Policy: no-referrer-when-downgrade
如果您需要任何其他信息,请随时询问
对此的任何帮助将不胜感激。
解决方案
推荐阅读
- python - 在 for 循环中生成时识别按钮
- puppet - puppet 资源如何在不编译失败的情况下检查 puppetmaster 上的数据源?
- c# - C#如何从IEnumerable中创建一个列表
- google-chrome-extension - Chrome 扩展错误:拒绝执行内联事件处理程序
- javascript - React-router API - 定义路由
- unity3d - Unity 找不到 C# 脚本
- r - 基于多条件创建一个新变量并在R中循环
- c - C - 零双变量不匹配条件
- webpack - 刷新后在 chrome 开发人员工具页面中保留打开的 webpack 源映射
- bootstrap-4 - Symfony Webpack Encore 和 FontAwesome 的编译错误