將 Apache 重定向到子文件夾中的不同服務
我有一個在 Apache/HTTPD 2.2 下執行 DokuWiki 的 CentOS 6.9 伺服器。此 wiki 安裝在
/var/www/html/dokuwiki
. 因此,當您鍵入 時myserver.com/dokuwiki
,它會進入 wiki。如果您鍵入myserver.com
,則會顯示一個簡單index.html
文件 (/var/www/html/index.html
),其中包含指向 Wiki 和 GitLab 的連結。現在我已經安裝了 GitLab 並將其配置為也使用 HTTPD(預設情況下它集成了 NGINX)。如果我自己啟動GitLab 和 DokuWiki ,它們都可以正常工作,但我找不到同時讓它們可見的方法。
我想要的是:如果使用者鍵入
myserver.com
,則顯示index.html
兩個連結:一個指向 wiki (myserver.com/dokuwiki
),另一個連結指向 GitLab 伺服器 (myserver.com/gitlab
)。通過點擊每個,使用者可以訪問所需的服務。發生的情況是,如果將gitlab 的配置優先於另一個(
00-gitlab.conf
例如,通過將名稱更改為顯示)因為它使用其他規則並且沒有匹配(我猜是由於 GitLab 的指令)。在這種情況下,GitLab 工作正常。myserver.com``myserver.com/dokuwiki``Not found "/"``Location
如果我將 Wiki 的配置放在優先位置,當我嘗試訪問時會收到 404 錯誤,
myserver.com/gitlab
因為此規則更通用,因此它會通過Location
指令忽略另一個。在這種情況下,索引和 Wiki 工作正常。這是兩者的虛擬主機配置,儲存在
/etc/httpd/conf.d
. 一切都是 SSL 並且工作正常。HTTP(埠 80)的配置幾乎相同,但我沒有在此處包含它。我也有NameVirtualHost *:443
在httpd.conf
.維基/根:
<VirtualHost *:443> ServerName myserver.com DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /etc/httpd/ssl/myserver.com.crt SSLCertificateKeyFile /etc/httpd/ssl/myserver.com.key </VirtualHost>
GitLab
<VirtualHost *:443> ServerName myserver.com ServerSignature Off ProxyPreserveHost On AllowEncodedSlashes NoDecode SSLEngine on SSLCertificateFile /etc/httpd/ssl/myserver.com.crt SSLCertificateKeyFile /etc/httpd/ssl/myserver.com.key SSLProtocol all -SSLv2 SSLHonorCipherOrder on SSLCipherSuite "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS" Header add Strict-Transport-Security: "max-age=15768000;includeSubdomains" <Location /gitlab> Order deny,allow Allow from all ProxyPassReverse http://127.0.0.1:8181 ProxyPassReverse http://myserver.com/gitlab </Location> RewriteEngine on #Forward all requests to gitlab-workhorse except existing files like error documents RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_URI} ^/uploads/.* RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE] # needed for downloading attachments DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public/ #Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up. ErrorDocument 404 /404.html ErrorDocument 422 /422.html ErrorDocument 500 /500.html ErrorDocument 502 /502.html ErrorDocument 503 /503.html # It is assumed that the log directory is in /var/log/httpd. # For Debian distributions you might want to change this to # /var/log/apache2. LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded ErrorLog /var/log/httpd/logs/myserver_error.log CustomLog /var/log/httpd/logs/myserver_forwarded.log common_forwarded CustomLog /var/log/httpd/logs/myserver_access.log combined env=!dontlog CustomLog /var/log/httpd/logs/myserver.log combined </VirtualHost>
謝謝。
您缺少該
ProxyPass
指令,並且您有ProxyPassReverse
兩次具有不同的值。只會使用其中之一。正確的應該是:
ProxyPass http://127.0.0.1:8181 ProxyPassReverse http://127.0.0.1:8181
你應該只有一個虛擬主機:
<VirtualHost *:443> ServerName myserver.com DocumentRoot /var/www/html SSLEngine on SSLCertificateFile /etc/httpd/ssl/myserver.com.crt SSLCertificateKeyFile /etc/httpd/ssl/myserver.com.key <Location /gitlab> Order deny,allow Allow from all ProxyPassReverse http://127.0.0.1:8181 ProxyPassReverse http://myserver.com/gitlab </Location> </VirtualHost>
此外,您必須在 gitlab 本身中配置正確的基本 URL。