【问题标题】:HTTPD with two different services in the same computer在同一台计算机上具有两个不同服务的 HTTPD
【发布时间】:2020-02-28 15:51:44
【问题描述】:

我有一个 CentOS 6.9 服务器,它在 HTTPD 2.2 下运行 DokuWiki。这个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),则会发生 wiki 的配置不起作用并且当您键入 myserver.commyserver.com/dokuwiki,它没有找到任何东西( Not found "/" 显示)因为它使用其他规则并且没有匹配项(我猜是由于 GitLab 的 Location 指令)。在这种情况下,GitLab 工作正常。

如果我优先考虑 Wiki 的配置,当我尝试访问 myserver.com/gitlab 时会收到 404 错误,因为此规则更通用,因此它会使用 Location 指令忽略另一个。在这种情况下,索引和 Wiki 工作正常。

以下是两者的虚拟主机配置,存储在 /etc/httpd/conf.d 中。一切都是 SSL 并且工作正常。 HTTP(端口 80)的配置几乎相同,但我没有在此处包含它。我在httpd.conf 中也有NameVirtualHost *:443

维基/根:

<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>

谢谢。

【问题讨论】:

  • 您的问题是两个文件都具有相同的ServerName,因此 Apache 首先读取的是获得服务的文件。您需要组合 VirtualHost 块并有一个单独的 Location 块,其中 / 为您的 index.html 提供服务器,/dokuwiki 为您的 wiki 提供服务,/gitlab 为 ProxyPass 提供服务
  • 你是绝对正确的。我修好了,谢谢。我发布了我的配置,它现在正在工作..

标签: apache gitlab httpd.conf


【解决方案1】:

我找到了解决方案。我只需要一个 VirtualHost 并正确定义我的 proxypass。

这是工作文件:

<VirtualHost *:443>
    ServerName myserver.com
    DocumentRoot /var/www/html
    SSLEngine on

    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"
    ServerSignature Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    SSLCertificateFile /etc/httpd/ssl/myserver.com.crt
    SSLCertificateKeyFile /etc/httpd/ssl/myserver.com.key

    Alias /gitlab  /opt/gitlab/embedded/service/gitlab-rails/public
    <Location /gitlab>
        Order deny,allow
        Allow from all

        ProxyPass http://127.0.0.1:8181
        ProxyPassReverse http://127.0.0.1:8181
        ProxyPassReverse http://myserver.com/gitlab
        RewriteEngine on

        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
        RewriteCond %{REQUEST_URI} ^/uploads/.*
        RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
        ErrorDocument 404 /404.html
        ErrorDocument 422 /422.html
        ErrorDocument 500 /500.html
        ErrorDocument 502 /502.html
        ErrorDocument 503 /503.html
  </Location>

  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>

【讨论】:

    猜你喜欢
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多