Apache 重定向到 https://www 然后代理到 localhost
Apache redirect to https://www and then proxy to localhost
我在 localhost:8180
上安装了一个 node.js 应用程序 运行。
我希望只能通过 https://www.example.com 从 Web 访问应用程序。
目标是将所有流向 http://example.com
、http://www.example.com
、https://example.com
的流量重定向到 https://www.example.com
。
我可以访问 Plesk 面板 v12.5.30。在这个面板中,我可以为 http 和 https 请求配置单独的 .htaccess 规则。面板看起来像这样:
Plesk Apache directives panel
我可以使用这个面板实现我的目标吗?
我已经为 http 和 https 尝试了以下规则,但出现代理错误。
http
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com [L,R=301]`
https
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST} [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://localhost:8180 [P]
ProxyPassReverse / http://localhost:8180/
我强烈建议使用 Nginx 指令,而不是像这样:
if ($scheme != https) {
return 301 https://www.example.com$request_uri;
}
您还可以在所有 .htaccess
文件代码之上尝试兼容性更好的 htaccess 代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
我在 localhost:8180
上安装了一个 node.js 应用程序 运行。
我希望只能通过 https://www.example.com 从 Web 访问应用程序。
目标是将所有流向 http://example.com
、http://www.example.com
、https://example.com
的流量重定向到 https://www.example.com
。
我可以访问 Plesk 面板 v12.5.30。在这个面板中,我可以为 http 和 https 请求配置单独的 .htaccess 规则。面板看起来像这样:
Plesk Apache directives panel
我可以使用这个面板实现我的目标吗?
我已经为 http 和 https 尝试了以下规则,但出现代理错误。
http
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com [L,R=301]`
https
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST} [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://localhost:8180 [P]
ProxyPassReverse / http://localhost:8180/
我强烈建议使用 Nginx 指令,而不是像这样:
if ($scheme != https) {
return 301 https://www.example.com$request_uri;
}
您还可以在所有 .htaccess
文件代码之上尝试兼容性更好的 htaccess 代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>