用于 Rails 应用程序 Gitlab 的 Apache2 ProxyPass

标签 apache redirect proxy apache2 proxypass

我正在尝试使用 Apache2 设置代理,以便传入到 的请求http://myipaddress.com 转至 http://localhost:3000/我在哪里运行 Gitlab(一个 rails 应用程序)。以下是我在 Ubuntu 10.04 上的 Apache 配置文件中的内容。我最初可以成功访问 gitlab 默认页面,但是我通过单击其他页面执行的任何后续请求都会转到 404 NOT FOUND 页面。我可以在任何这些失败的重定向前手动输入/gitlab/,它们工作得很好。如何在初始请求之后的每个重定向请求之后重写/gitlab/来完成这项工作?

## Setup a proxy which listens on the port that gitlabh does ( from start_server.sh )
ProxyRequests Off
ProxyPass /gitlab/ http://localhost:3000/
ProxyPassReverse /gitlab/ http://localhost:3000/
#DocumentRoot /home/gitlabhq/gitlabhq/public
<Proxy http://localhost:3000/>
  Order deny,allow
  Allow from all
</Proxy>

我知道我可以拥有下面的代码,这将解决我的问题。但是我不知道如何修改gitlab rails服务的前缀。我真的很感激一些帮助!
ProxyPass /gitlab/ http://localhost:3000/gitlab/
ProxyPassReverse /gitlab/ http://localhost:3000/gitlab/

更新:

感谢弗里克的评论,我已经非常接近解决这个问题了。以下是我的 http.conf 文件的一部分。唯一的问题是,当我点击主页按钮或 gitlab 应用程序上的 Logo 时,它会尝试重定向到 gitlab/,这给了我来自 Apache2 的基本 index.html 文件说“它有效!”。如何配置它以允许我简单地获取/gitlab 并将我带到 gitlab 的根主视图?谢谢!
## For Gitlab using Apache2 Passenger
## Install on Ubuntu by:
## sudo gem install passenger && sudo passenger-install-apache2-module
## but only after running the install_and_configure_git.py script
## and creating a soft link to the rails gitlab /public directory like so:
## sudo ln -s /home/gitlabhq/gitlabhq/public /var/www/gitlab
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13
PassengerRuby /usr/local/bin/ruby
<VirtualHost *:80>

        ServerName gitlab

        ## Set the overall Document Root
        DocumentRoot /var/www
        <Directory /var/www>
                Allow from all
        </Directory>

        ## Set the Rails Base URI
        RackBaseURI /gitlab
        RailsBaseURI /gitlab
        <Directory /var/www/gitlab>
                Allow from all
                Options -MultiViews
        </Directory>

</VirtualHost>

最佳答案

我遇到了this gist这对我有用。万一它死了,我会重新发布它。

unicorn 配置文件

编辑文件/home/gitlab/gitlab/config/unicorn.rb
找线收听"#{app_dir}/tmp/sockets/gitlab.socket"并发表评论。取消注释行听 "127.0.0.1:8080"
Apache所需的模块

  • 须藤 a2enmod 代理
  • 须藤 a2enmod 代理平衡器
  • sudo a2enmod proxy_http
  • sudo a2enmod 重写

  • /home/gitlab/gitlab/config/gitlab.conf
    <VirtualHost *:80>
      ServerName git.domain.com
    
      # Point this to your public folder of teambox
      DocumentRoot /home/gitlab/gitlab
    
      RewriteEngine On
    
      <Proxy balancer://unicornservers>
        BalancerMember http://127.0.0.1:8080
      </Proxy>
    
      # Redirect all non-static requests to thin
      RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
      RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
    
      ProxyPass / balancer://unicornservers/
      ProxyPassReverse / balancer://unicornservers/
      ProxyPreserveHost on
    
      <Proxy *>
        Order deny,allow
        Allow from all
      </Proxy>
    
      # Custom log file locations
      ErrorLog  /var/log/apache2/gitlab_error.log
      CustomLog /var/log/apache2/gitlab_access.log combined
    </VirtualHost>
    

    关于用于 Rails 应用程序 Gitlab 的 Apache2 ProxyPass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10954516/

    相关文章:

    javascript - 通过 URL 触发 'onClick',但不访问该 URL

    python - 为什么 Tor 无法访问本地主机页面

    Apache Tomcat 和 Mod_jk

    javascript - 不能包含 javascript(401 错误)

    c# - 如何执行 HTTP POST 并将用户重定向到外部站点?

    python-requests 认证代理 httplib.BadStatusLine

    java - 使用内部类强制转换代理 Java 类

    php - apache mod_security 说 - 访问被拒绝错误

    php - Apache 服务器上的 500 错误 - "AllowOverride not allowed here"

    apache - Htaccess 重定向命令不区分大小写