Apache2 ProxyPass for Rails App Gitlab
我试图设置与Apache2的代理,以便传入的请求http://myipaddress.com去http://localhost:3000/
我有Gitlab(一个Rails应用程序)运行。 以下是我在Ubuntu 10.04的Apacheconfiguration文件中所拥有的内容。 我最初可以成功访问gitlab的默认页面,但是之后通过点击其他页面来执行的任何后续请求都会转到404 NOT FOUND页面。 我可以手动input/ gitlab /在任何这些失败的redirect前,他们工作得很好。 在初始请求之后,如何在不重写每个redirect请求的情况下重写/ 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/
更新:
感谢Friek的评论,我已经接近解决这个问题了。 下面是我的http.conf文件的一部分。 唯一的问题是,当我点击主页button或gitlab应用程序的标志,它试图redirect到gitlab /这给了我从Apache2基本index.html文件说'它的工作!'。 我怎么能configuration这个让我简单地得到/ 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>
我遇到了这个为我工作的要点 。 如果它死了,我会重新发布。
独angular兽configuration文件
编辑文件/home/gitlab/gitlab/config/unicorn.rb
查找线路"#{app_dir}/tmp/sockets/gitlab.socket"
并对其进行注释。 取消注释听"127.0.0.1:8080"
Apache所需的模块
- sudo a2enmod代理
- sudo a2enmod proxy_balancer
- 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>
<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>
这些设置在您的httpd.conf或您的网站configuration文件应该做的,请删除反向代理设置,如果你有任何和尝试,它将工作。
如果你有以上的configuration,请删除下面的行,
ProxyPass /gitlab/ http://localhost:3000/gitlab/ ProxyPassReverse /gitlab/ http://localhost:3000/gitlab/ Proxy on
重新启动您的networking服务器
service apache2 restart
对不起,在这个老问题上的post…但基于主要问题的更新文本,我已经build立了一个function的要点与所有步骤:
这是为了防止有人遇到这个问题。
这帮助了我,注意ProxyPassReverse行。 我的完整问题和解决scheme是在https://stackoverflow.com/a/22390543/3112527 。
<IfModule mod_ssl.c> <VirtualHost *:443> Servername gitlab.my_domain.com ServerAdmin my_admin@my_domain.com SSLCertificateFile /etc/apache2/ssl.crt/gitlab_my_domain.crt SSLCertificateKeyFile /etc/apache2/ssl.crt/gitlab_my_domain_private.key SSLCACertificateFile /etc/apache2/ssl.crt/gitlab.ca-bundle ##### All the other Apache SSL setup skipped here for StackOverflow #### ProxyPreserveHost On <Location /> # New authorization commands for apache 2.4 and up # http://httpd.apache.org/docs/2.4/upgrading.html#access Require all granted # For relative URL root "host:your_gitlab_port/relative_root" #ProxyPassReverse http://127.0.0.1:8085/gitlab #ProxyPassReverse https://gitlab.my_domain.com/gitlab # For non-relative URL root ProxyPassReverse http://127.0.0.1:8085 ProxyPassReverse https://gitlab.my_domain.com/ </Location> # apache equivalent of nginx try files # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files # https://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA] RequestHeader set X_FORWARDED_PROTO 'https' # needed for downloading attachments DocumentRoot /home/git/gitlab/public #Set up apache error documents, if back end goes down (ie 503 error) then a maintenance/deploy page is thrown up. ErrorDocument 404 /404.html ErrorDocument 422 /422.html ErrorDocument 500 /500.html ErrorDocument 503 /deploy.html LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded ErrorLog /var/log/apache2/gitlab-ssl_error.log CustomLog /var/log/apache2/gitlab-ssl_forwarded.log common_forwarded CustomLog /var/log/apache2/gitlab-ssl_access.log combined env=!dontlog CustomLog /var/log/apache2/gitlab-ssl.log combined </VirtualHost> </IfModule>
(从https://github.com/gitlabhq/gitlab-recipes/blob/master/web-server/apache/gitlab-ssl-apache2.4.conf )
当我在使用Apache(在端口80上)设置Rails +独angular兽来代理到独angular兽(在端口3000上)时遇到的错误时,我在这里结束了。 万一它对其他人有用,这里是我的configuration:
<VirtualHost example.com:80> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com ProxyPreserveHost On <Location /> Require all granted ProxyPassReverse http://example.com:3000 </Location> RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule .* http://example.com:3000%{REQUEST_URI} [P,QSA] DocumentRoot /home/user/rails-dir/public ErrorDocument 404 /404.html ErrorDocument 422 /422.html ErrorDocument 500 /500.html ErrorDocument 503 /deploy.html LogLevel warn ErrorLog /home/user/rails-dir/log/apache-error.log CustomLog /home/user/rails-dir/log/apache-access.log combined </VirtualHost>