Apache-2.4
CentOS 7 (WHM) 上 nodejs 伺服器的 Apache 反向代理
我正在嘗試在伺服器上設置我的網站。我已經上傳了它,它目前正在伺服器上執行,但是當我嘗試在域上設置反向代理以便我可以訪問該站點時,問題就來了。我遵循了關於如何進行反向代理的 WHM 文件,它確實有效,但它也重定向了子域。以下是我修改單個虛擬主機所遵循的教程。
https://docs.cpanel.net/ea4/apache/modify-apache-virtual-hosts-with-include-files/
簡而言之,我希望能夠在不影響我的子域 webmail.example.com 的情況下訪問我的站點 example.com。下面是我的conf文件
ServerName example.com ServerAlias www.example.com ProxyRequests Off <Proxy *> Require all granted </Proxy> ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/
以下是我嘗試更改位於 httpd.conf 文件中的同一虛擬主機的預設設置
<VirtualHost 196.41.123.76:80> ServerName example.com ServerAlias mail.example.com www.example.com DocumentRoot /home/gusqooqw/public_html ServerAdmin webmaster@example.com UseCanonicalName Off ## User gusqooqw # Needed for Cpanel::ApacheConf <IfModule userdir_module> <IfModule !mpm_itk.c> <IfModule !ruid2_module> <IfModule !mod_passenger.c> UserDir enabled gusqooqw </IfModule> </IfModule> </IfModule> </IfModule> # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4. # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in # the user's .htaccess file. For more information, please read: # http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser <IfModule include_module> <Directory "/home/gusqooqw/public_html"> SSILegacyExprParser On </Directory> </IfModule> <IfModule suphp_module> suPHP_UserGroup gusqooqw gusqooqw </IfModule> <IfModule suexec_module> <IfModule !mod_ruid2.c> SuexecUserGroup gusqooqw gusqooqw </IfModule> </IfModule> <IfModule ruid2_module> RMode config RUidGid gusqooqw gusqooqw </IfModule> <IfModule mpm_itk.c> # For more information on MPM ITK, please read: # http://mpm-itk.sesse.net/ AssignUserID gusqooqw gusqooqw </IfModule> <IfModule mod_passenger.c> PassengerUser gusqooqw PassengerGroup gusqooqw </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ /home/gusqooqw/public_html/cgi-bin/ </IfModule> # Global DCV Rewrite Exclude <IfModule rewrite_module> RewriteOptions Inherit </IfModule> Include "/etc/apache2/conf.d/userdata/std/2_4/gusqooqw/example.com/*.conf" # To customize this VirtualHost use an include file at the following location # Include "/etc/apache2/conf.d/userdata/std/2_4/gusqooqw/example.com/*.conf" <VirtualHost>
下面是在 httpd.conf 中找到的預設 webmail 虛擬主機
<VirtualHost 196.41.123.76:443> ServerName example.com ServerAlias mail.example.com www.example.com cpcalendars.example.com webdisk.example.com webmail.example.com cpcontacts.example.com cpanel.example.com DocumentRoot /home/gusqooqw/public_html ServerAdmin webmaster@example.com UseCanonicalName Off ## User gusqooqw # Needed for Cpanel::ApacheConf <IfModule userdir_module> <IfModule !mpm_itk.c> <IfModule !ruid2_module> <IfModule !mod_passenger.c> UserDir enabled gusqooqw </IfModule> </IfModule> </IfModule> </IfModule> # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4. # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in # the user's .htaccess file. For more information, please read: # http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser <IfModule mod_include.c> <Directory "/home/gusqooqw/public_html"> SSILegacyExprParser On </Directory> </IfModule> <Proxymatch ^https?://127\.0\.0\.1:(2082|2083|2077|2078|2079|2080|2086|2087|2095|2096)/> <IfModule security2_module> SecRuleEngine Off </IfModule> </Proxymatch> IfModule mod_suphp.c> suPHP_UserGroup gusqooqw gusqooqw </IfModule> <IfModule suexec_module> <IfModule !mod_ruid2.c> SuexecUserGroup gusqooqw gusqooqw </IfModule> </IfModule> <IfModule ruid2_module> RMode config RUidGid gusqooqw gusqooqw </IfModule> <IfModule mpm_itk.c> # For more information on MPM ITK, please read: # http://mpm-itk.sesse.net/ AssignUserID gusqooqw gusqooqw </IfModule> <IfModule mod_passenger.c> PassengerUser gusqooqw PassengerGroup gusqooqw </IfModule> <IfModule alias_module> ScriptAlias /cgi-bin/ /home/gusqooqw/public_html/cgi-bin/ </IfModule> <IfModule ssl_module> SSLEngine on SSLCertificateFile /var/cpanel/ssl/apache_tls/example.com/combined SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown <Directory "/home/gusqooqw/public_html/cgi-bin"> SSLOptions +StdEnvVars </Directory> </IfModule> Include "/etc/apache2/conf.d/userdata/ssl/2_4/gusqooqw/example.com/*.conf" # To customize this VirtualHost use an include file at the following location # Include "/etc/apache2/conf.d/userdata/ssl/2_4/gusqooqw/example.com/*.conf" <IfModule headers_module> RequestHeader set X-HTTPS 1 </IfModule> RewriteEngine On RewriteCond %{HTTP_HOST} =cpanel.example.com [OR] RewriteCond %{HTTP_HOST} =cpanel.example.com:443 RewriteCond %{HTTP:Upgrade} !websocket [nocase] RewriteRule ^/(.*) /___proxy_subdomain_cpanel/$1 [PT] ProxyPass "/___proxy_subdomain_cpanel" "http://127.0.0.1:2082" max=1 retry=0 RewriteCond %{HTTP_HOST} =cpcalendars.example.com [OR] RewriteCond %{HTTP_HOST} =cpcalendars.example.com:443 RewriteCond %{HTTP:Upgrade} !websocket [nocase] RewriteRule ^/(.*) /___proxy_subdomain_cpcalendars/$1 [PT] ProxyPass "/___proxy_subdomain_cpcalendars" "http://127.0.0.1:2079" max=1 retry=0 RewriteCond %{HTTP_HOST} =cpcontacts.example.com [OR] RewriteCond %{HTTP_HOST} =cpcontacts.example.com:443 RewriteCond %{HTTP:Upgrade} !websocket [nocase] RewriteRule ^/(.*) /___proxy_subdomain_cpcontacts/$1 [PT] ProxyPass "/___proxy_subdomain_cpcontacts" "http://127.0.0.1:2079" max=1 retry=0 RewriteCond %{HTTP_HOST} =webdisk.example.com [OR] RewriteCond %{HTTP_HOST} =webdisk.example.com:443 RewriteCond %{HTTP:Upgrade} !websocket [nocase] RewriteRule ^/(.*) /___proxy_subdomain_webdisk/$1 [PT] ProxyPass "/___proxy_subdomain_webdisk" "http://127.0.0.1:2077" max=1 retry=0 RewriteCond %{HTTP_HOST} =webmail.example.com [OR] RewriteCond %{HTTP_HOST} =webmail.example.com:443 RewriteCond %{HTTP:Upgrade} !websocket [nocase] RewriteRule ^/(.*) /___proxy_subdomain_webmail/$1 [PT] ProxyPass "/___proxy_subdomain_webmail" "http://127.0.0.1:2095" max=1 retry=0 RewriteCond %{HTTP:Upgrade} websocket [nocase] RewriteCond %{HTTP_HOST} =cpanel.example.com [OR] RewriteCond %{HTTP_HOST} =cpanel.example.com:443 RewriteRule ^/(.*) /___proxy_subdomain_ws_cpanel/$1 [PT] RewriteCond %{HTTP:Upgrade} websocket [nocase] RewriteCond %{HTTP_HOST} =webmail.example.com [OR] RewriteCond %{HTTP_HOST} =webmail.example.com:443 RewriteRule ^/(.*) /___proxy_subdomain_ws_webmail/$1 [PT] </VirtualHost>
因此,在聯繫了 cpanel 支持後,他們無法回答為什麼我上面使用的方法不起作用,他們提供了替代解決方案。我最終在 Cpanel 上使用了一個名為 Application manager 的界面。這是在 cpanel 伺服器上安裝 nodejs 應用程序的最簡單方法。以下是有關如何使用它來執行您的應用程序的文件
https://docs.cpanel.net/knowledge-base/web-services/how-to-install-a-node.js-application/
希望這可以幫助某人