将 Nginx 代理移植到 apache 虚拟主机

将 Nginx 代理移植到 apache 虚拟主机

我在当时使用 Nginx 的服务器上安装了 Gitlab,但后来我们切换到了 Apache2,似乎无法让 mywebsite.com:3000 引用 /home/gitlab/gitlab/public,而在 Nginx 中,它运行正常。目前,当向 mywebsite.com:3000 发出请求时,页面实际上从未加载。请问您能告诉我哪里出错了吗?

阿帕奇:

Listen 3000
<VirtualHost *:3000>
  DocumentRoot /home/gitlab/gitlab/public
  ErrorLog /var/log/apache2/gitlab_error_log
  CustomLog /var/log/apache2/gitlab_access_log combined

  <Proxy balancer://unicornservers>
      BalancerMember http://127.0.0.1:3000
  </Proxy>

  <Directory /home/gitlab/gitlab/public>
    AllowOverride All
    Options -MultiViews
  </Directory>

  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]

  ProxyPass /uploads !
  ProxyPass / balancer://unicornservers/
  ProxyPassReverse / balancer://unicornservers/
  ProxyPreserveHost on

   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>
</VirtualHost>

Nginx的:

upstream gitlab {
  server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen 3000 default_server;         # e.g., listen 192.168.1.1:80;
  server_name 198.211.120.58;     # e.g., server_name source.example.com;
  root /home/gitlab/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;

    proxy_pass http://gitlab;
  }
}

答案1

第一件事

当仅使用端口的 apache 的 Listen 指令时,会强制 apache 侦听所有可用的 IP/接口,这是一个通配符条目,这无疑会干扰您在 localhost:3000 上侦听的负载平衡器,如果我没记错的话,这会导致 apache 无法启动,因为它可以绑定到该端口。但请尝试以下操作并告诉我。

您需要指定希望 Apache 监听的 IP。在您的例子中,它应该是

Listen 198.211.120.58:3000. 

最后,你需要指定你的 apache 虚拟主机,例如

<VirtualHost 198.211.120.58:3000>

...

</VirtualHost>

问候,丹尼

相关内容