Rails App (Redmine) not served via Apache - ruby-on-rails

I have a website, under which I wanted to install redmine(rails application) so that I could access redmine as a subdirectory (http://mywebsite.foobar.com/redmine). I have installed redmine, and I can access it locally (lynx http://localhost:3000), but when I try to access it via a browser by typing its address, I get the list of files. How can I make the application accessible? I do have passenger installed. My virtualhost file is as follows:
1 <VirtualHost *:80>
2 ServerName mywebsite.foobar.com
3 ServerAlias www.mywebsite.foobar.com
4 ServerAdmin admin#foobar.com
5 Redirect permanent / https://mywebsite.foobar.com/
6
7 DocumentRoot /path/to/www/
8 ReadmeName README.html
9 IndexOptions SuppressHTMLPreamble
10
11 <Directory "/path/to/www">
12 Options Indexes FollowSymLinks
13 Order allow,deny
14 Allow from all
15 → Require all granted
16 IndexIgnore ..
17 IndexIgnore README.html
18 </Directory>
19
20 RailsEnv production
21 → → RewriteEngine on
22 → → → Alias /redmine /path/to/www/redmine/public/
23 → → → <Directory "/path/to/www/redmine/public/">
24 → → → → Order allow,deny
25 → → → → allow from all
26 → → Options +Indexes +FollowSymLinks -MultiViews +ExecCGI
27 → → Require all granted
28 → → → </Directory>
29
30
31
32 Include aliases.conf
33 Include /etc/apache2/foobar/security.conf
34 </VirtualHost>
Also my https virtualhost looks like this:
1 <VirtualHost *:443>
2 SSLEngine On
3 SSLCertificateFile /etc/apache2/ssl/foobar.crt
4 SSLCertificateKeyFile /etc/apache2/ssl/foobar.key
5 SSLCertificateChainFile /etc/apache2/ssl/gd_bundle.crt
6
7 ServerName mywebsite.foobar.com
8 ServerAlias www.mywebsite.foobar.com
9 ServerAdmin admin#foobar.com
10 UseCanonicalName Off
11
12 DocumentRoot /path/to/www/
13 RailsEnv Production
14 RewriteEngine on
15
16 <Directory "/path/to/www/">
17 Require all granted
18 </Directory>
19
20
21 Alias /redmine /path/to/www/redmine/public
22
23 <Location /redmine>
24 PassengerBaseURI /redmine
25 PassengerAppRoot /path/to/www/redmine/public/
26 </Location>
27
28 <Directory "/path/to/www/redmine/public">
29 Order allow,deny
30 allow from all
31 Options +Indexes +FollowSymLinks -MultiViews +ExecCGI
32 Require all granted
33 </Directory>
34
35 Include /etc/apache2/foobar/security.conf
36
37
38 </VirtualHost>
P.S: The website itself is served as a virtualhost, so redmine would be a directory under virtual host.

Ok. So I found my solution on passenger documentation: I basically had to change the options. The related options look like:
39 Alias /redmine /path/to/www/redmine/public/
40 <Location /redmine>
41 PassengerBaseURI /redmine
42 PassengerAppRoot /path/to/www/redmine
43 </Location>
44 <Directory /path/to/www/redmine/public>
45 Allow from all
46 Options +Indexes +FollowSymLinks -MultiViews +ExecCGI
47 Require all granted
48 </Directory>

Related

Nexus returns error 502 (Bad Gateway) when publishing artifacts

I've just completed the installation of Sonatype Nexus 3.2.1-01 and I'm trying to publish some artifacts using a Jenkins job and the Nexus Artifact Uploader 2.9 plugin.
The upload starts fine:
100 % completed (572 kB / 572 kB).
But then it throws the the error:
Return code is: 502, ReasonPhrase:Bad Gateway.
Both the Jenkins and Nexus servers run behind a reverse proxy which I believe are the source of the issue.
The Apache log seems to suggest that the request was not replied by Nexus:
[Thu Apr 06 18:50:46.128569 2017] [proxy:error] [pid 10327] (32)Broken pipe:
[client some_ip:57928] AH01084: pass request body failed to 0.0.0.0:8081 (0.0.0.0)
[Thu Apr 06 18:50:46.128649 2017] [proxy_http:error] [pid 10327] [client some_ip:57928] AH01097: pass request body failed to 0.0.0.0:8081 (0.0.0.0) from some_ip ()
This is my VirtualHost config in Apache for the Sonar server:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin some#email.com
ServerName some.website.com
ServerAlias nsome.website.com
DocumentRoot /srv/www/nexus/public_html/
ErrorLog /srv/www/nexus/logs/error.log
CustomLog /srv/www/nexus/logs/access.log combined
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8081/
ProxyPassReverse / http://0.0.0.0:8081/
ProxyPassReverse / https://some.website.com/
SSLCertificateFile /etc/letsencrypt/live/some.website.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/some.website.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/some.website.com/chain.pem
</VirtualHost>
</IfModule>
I've tried to add the following, as explained in other answers, but did not help:
1) Disabling the check on the SSL certificates (although these are valid):
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
2) Forcing the requests headers:
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
3) Settting the timeouts and keepalive options in the ProxyPass line:
ProxyPass / http://0.0.0.0:8081/ retry=1 acquire=3000 timeout=600 Keepalive=On
At the end the error 502 (bad gateway) had nothing to do with the root cause of the problem. The version listed on the artifact to be published for the snapshot version did not comply with the Nexus policy and this was triggering the error.
In my case it was an upgrade issue from Nexus2 to Nexus3: here the component URL changed from https://nexus.yourcompany.com/content/repositories/releases
to https://nexus.yourcompany.com/repository/releases.
I was having the same issue because my python script skip basic authentication. When forced, the problem was resolved.
It was weird because uploading a 'tar.gz' works fine but a 'zip' give me the 502 error.
Add this to your pom file
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

Incomplete response received from application Rails 4 Passenger error

I have a Rails 4.2.6 application with Passenger 5.0.28 on Ubuntu 14.04 x64.
After successful deployment using Capistrano, I can't open website. And I even can't find log files that will indicate the problem. After some research, I have found out that the most common problem is missing secret_key_base env var.
So here is my pretty simple apache config file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my.server.com
DocumentRoot /var/www/my_server/current/public
PassengerRuby /home/deployer/.rvm/gems/ruby-2.2.2/wrappers/ruby
<Directory />
Options FollowSymLinks
AllowOverride None
RailsEnv staging_v4
</Directory>
<Directory /var/www/my_server/current/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-v4.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access-v4.log combined
</VirtualHost>
When I try to open my app In see the error:
Incomplete response received from application
Logs tail -f /var/log/apache2/*
==> /var/log/apache2/access-v4.log <==
10.0.14.224 - - [09/Jun/2016:18:47:22 +0600] "GET / HTTP/1.1" 502 343 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36"
10.0.14.224 - - [09/Jun/2016:18:47:23 +0600] "GET /favicon.ico HTTP/1.1" 200 1449 "http:/my.server.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36"
Error log is empty.
My application logs in /var/www/my_server/current/log also empty
So what I did so far:
I put actual string inside /var/www/my_server/current/config/secrets.yml
I added export SECRET_KET_BASE=<string> inside /etc/profile, /home/deployer/.bash_profile, /etc/apache2/envvars
Any thoughts? Where should I gather more information from server?
I have similar issue on Rails 5.2, apache, passenger
The solution was to put this line in the configuration files (conifg/initializers)
Rack::Utils.multipart_part_limit = 0

Passenger 5.0.21 error: Cannot connect to the Passenger core

I have problem with deploying RoR-app with apache2+passenger.
OS is debian-like Astra Linux.
Kerberos auth with GSSAPI is enabled.
passenger-status shows:
Version : 5.0.21
Date : 2016-04-22 12:29:13 +0300
Instance: Dt5dmAVr (Apache/2.2.22 (Debian) mod_auth_kerb/5.4 Phusion_Passenger/5.0.21)
Phusion Passenger is currently not serving any applications.
With attempt to access app page from browser I get error message in /var/log/apache2/error.log :
[ 2016-04-22 12:23:58.4672 21392/7f741705c780 age/Cor/CoreMain.cpp:234 ]: Passenger core running in multi-application mode.
[ 2016-04-22 12:23:58.4685 21392/7f741705c780 age/Cor/CoreMain.cpp:707 ]: Passenger core online, PID 21392
[ 2016-04-22 12:23:58.4897 21407/7f4819471780 age/Ust/UstRouterMain.cpp:504 ]: Starting Passenger UstRouter...
[ 2016-04-22 12:23:58.4912 21407/7f4819471780 age/Ust/UstRouterMain.cpp:317 ]: Passenger UstRouter online, PID 21407
[Fri Apr 22 12:23:58 2016] [notice] Apache/2.2.22 (Debian) mod_auth_kerb/5.4 Phusion_Passenger/5.0.21 configured -- resuming normal operations
[ 2016-04-22 12:24:18.0666 21428/7f3a64646780 apa/Hooks.cpp:703 ]: Unexpected error in mod_passenger: Cannot connect to the Passenger core at unix:/tmp/passenger.N6n3OMb/agents.s/core
Backtrace:
in 'Passenger::FileDescriptor Hooks::connectToCore()' (Hooks.cpp:305)
in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:573)
With passenger-5.0.27 everything looks same.
Passenger was installed as gem.
/etc/apache2/mods-enabled/passenger.load:
LoadModule passenger_module /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.21/buildout/apache2/mod_passenger.so
/etc/apache2/mods-enabled/passenger.conf:
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.21
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>
/etc/apache2/sites-enabled/myapp:
<VirtualHost *:80>
ServerName myapp.ru
ServerAlias www.myapp.ru
ServerAdmin webmaster#localhost
DocumentRoot /var/www/myapp/public
RailsEnv production
<Directory /var/www/myapp/public/>
AuthType Kerberos
KrbAuthRealms EXAMPLE.RU
KrbServiceName HTTP/astra-server.example.ru
Krb5Keytab /etc/apache2/keytab
KrbMethodNegotiate on
KrbMethodK5Passwd off
require valid-user
Options Indexes FollowSymLinks MultiViews
AllowOverride None
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel warn
</VirtualHost>
Any help?
PassengerInstanceRegistryDir option helped me.
UPDATE
Whole solution for Apache+Passenger sockets processing on Astra Linux SE:
Apache user - www-data (/etc/apache2/envvars)
Passenger user switching is on (by default)
Passenger instance dir is moved to /var/passenger (PassengerInstanceRegistryDir option in /etc/apache2/mods-available/passenger.conf)
Astra Linux specific - www-data user has Linux (CAP_SETGID, CAP_SETUID) and PARSEC (PARSEC_CAP_PRIV_SOCK, PARSEC_CAP_SETMAC) priviledges. This priviledges can be set via usercaps command.
Directories /var/www, /var/passenger are owned by www-data
It could be that your /tmp dir is being cleaned by something. Check if the /tmp dir from the log actually exists or not if you see the error. You can fix that by stopping the cleaning or changing the PassengerInstanceRegistryDir to another place than /tmp.
Another possibility is that your shell is exiting somehow (Passenger uses the shell to execute commands, which will fail if the shell exits prematurely).
Either way setting the PassengerLogLevel to 7 should provide more information.

Rails 2 public folder: No route matches assets

I am working on a legacy Ruby on Rails application which is running under Ruby 1.9 and Rails 2.3.18.
I am serving the application through Apache with Passenger.
I am getting errors in the production.log which indicate that there is something wrong with how Rails or the web server is treating the public folder, e.g.
ActionController::RoutingError (No route matches "/javascripts/picnet.table.filter.min.js" with {:method=>:get})
All the required assets which are causing the errors are in the application public folder. Note that this is under Rails 2 not Rails 3 or 4.
My Apache host entry for the application looks like this:
<VirtualHost 127.0.0.1:443>
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/Users/evanbrown/Documents/apache-keys/server.crt"
SSLCertificateKeyFile "/Users/evanbrown/Documents/apache-keys/server.key"
ServerAdmin me#localhost
DocumentRoot "/Users/evanbrown/Documents/bl-app/public"
ServerName blapp.localhost
ServerAlias blapp.localhost
ErrorLog "/private/var/log/apache2/localhost-error.log"
PassengerRuby "/Users/evanbrown/.rvm/gems/ruby-1.9.3-p547#rails2/wrappers/ruby"
CustomLog "/private/var/log/apache2/localhost-access.log" common
<Directory "/Users/evanbrown/Documents/bl-app/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Options -MultiViews
PassengerAppEnv production
</Directory>
</VirtualHost>
The application is being served correctly by Passenger but since all the stylesheets and Javascripts in the public folder are causing routing errors, the output is all wrong.
I have read lots of posts that state that a misconfigured config.serve_static_assets can cause these problems but this seems to be for Rails 3 only as there is no option serve_static_assets under config in Rails 2.
My public folder is owned by the Apache user and group, which I understand is _www:_www under OS X.
-rwxrwxrwx 1 _www _www 947 5 Nov 11:20 404.html
-rwxrwxrwx 1 _www _www 930 5 Nov 11:20 422.html
-rwxrwxrwx 1 _www _www 948 5 Nov 11:20 500.html
-rwxrwxrwx 1 _www _www 0 5 Nov 11:20 favicon.ico
-rwxrwxrwx 1 _www _www 14571 5 Nov 11:20 favicon.png
drwxrwxrwx 4 _www _www 136 5 Nov 11:20 images
drwxrwxrwx 11 _www _www 374 5 Nov 11:20 javascripts
-rwxrwxrwx 1 _www _www 204 5 Nov 11:20 robots.txt
drwxrwxrwx 4 _www _www 136 5 Nov 11:20 stylesheets
Can anyone help me to find out what the solution to this problem is? Many thanks for your help.

Redmine 2.0.1 - missing CSS?

The version that I'm using:
Redmine version 2.0.1.stable
Ruby version 1.8.7 (i386-linux)
Rails version 3.2.3
Environment production
Database adapter MySQL
The strange thing is after pressing Ctrl+F5 a few times, I will get something like this:
I can't find any interesting in the production.log:
Started GET "/admin/info" for 192.168.3.40 at Sat Jun 23 21:14:50 +0700 2012
Processing by AdminController#info as HTML
Rendered admin/info.html.erb within layouts/admin (2.2ms)
Rendered admin/_menu.html.erb (7.8ms)
Rendered layouts/base.html.erb (72.9ms)
Completed 200 OK in 93ms (Views: 79.1ms | ActiveRecord: 8.3ms)
/etc/httpd/conf.d/passenger.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.12
PassengerRuby /usr/bin/ruby
/etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName redmine.domain.vn
ServerAdmin quanta#domain.vn
DocumentRoot /var/www/html/redmine/public/
RailsBaseURI /
ErrorLog logs/redmine.error_log
<Directory "/var/www/html/redmine/public/">
Options -MultiViews
Order allow,deny
Allow from all
AllowOverride none
Satisfy Any
</Directory>
</VirtualHost>
There is no .htaccess file in the public folder that might cause the problems with passenger:
ls -la /var/www/html/redmine/public/
-rw-rw-r-- 1 apache apache 485 May 28 14:25 404.html
-rw-rw-r-- 1 apache apache 674 May 28 14:25 500.html
-rwxr-xr-x 1 apache apache 473 Jun 2 11:34 dispatch.fcgi
-rwxrwxr-x 1 apache apache 473 May 28 14:25 dispatch.fcgi.example
-rw-rw-r-- 1 apache apache 7886 May 28 14:25 favicon.ico
drwxrwxr-x 2 apache apache 4096 May 28 14:25 help
-rw-rw-r-- 1 apache apache 1441 May 28 14:25 htaccess.fcgi.example
drwxrwxr-x 4 apache apache 4096 May 28 14:25 images
-rw-r--r-- 1 apache apache 20 Jun 23 18:59 info.php
drwxrwxr-x 4 apache apache 4096 May 28 14:25 javascripts
drwxrwxr-x 2 apache apache 4096 May 28 14:25 stylesheets
drwxrwxr-x 4 apache apache 4096 May 28 14:25 themes
Any thoughts?
UPDATE Sat Jun 23 22:50:44 ICT 2012
The source when missing CSS:
<link href="/themes/classic/stylesheets/I.application.css,q1338189946.pagespeed.cf.0ULULhmylO.css" media="all" rel="stylesheet" type="text/css"/>
<script src="/javascripts/prototype.js,q1338189946.pagespeed.jm.ix8Kb1Gh8H.js" type="text/javascript"></script>
<script src="/javascripts/effects.js,q1338189946.pagespeed.jm.2gOWX1ohLv.js" type="text/javascript"></script>
<script src="/javascripts/dragdrop.js,q1338189946.pagespeed.jm.vpl0THRgUC.js" type="text/javascript"></script>
<script src="/javascripts/controls.js,q1338189946.pagespeed.jm.-zBskbSR2S.js" type="text/javascript"></script>
<script src="/javascripts/rails.js,q1338189946.pagespeed.jm.unwctb3Jeq.js" type="text/javascript"></script>
<script src="/javascripts/application.js,q1338189946.pagespeed.jm.Su1eFnevwF.js" type="text/javascript"></script>
and this shows the page with CSS:
<link href="/themes/classic/stylesheets/application.css?1338189946" media="all" rel="stylesheet" type="text/css"/>
<script src="/javascripts/prototype.js?1338189946" type="text/javascript"></script>
<script src="/javascripts/effects.js?1338189946" type="text/javascript"></script>
<script src="/javascripts/dragdrop.js?1338189946" type="text/javascript"></script>
<script src="/javascripts/controls.js?1338189946" type="text/javascript"></script>
<script src="/javascripts/rails.js?1338189946" type="text/javascript"></script>
<script src="/javascripts/application.js?1338189946" type="text/javascript"></script>
Where these weird characters that cause the wrong href and src path come from?
It seems that the culprit is... mod_pagespeed. I see the below error when turning on the Firebug:
"NetworkError: 500 Internal Server Error - http://redmine.domain.vn/javascripts/prototype.js,q1338189946.pagespeed.jm.ix8Kb1Gh8H.js"
Disable it and now Redmine is working fine:
<VirtualHost *:80>
ServerName redmine.domain.vn
ServerAdmin quanta#domain.vn
DocumentRoot /var/www/html/redmine/public/
RailsBaseURI /
ErrorLog logs/redmine.error_log
ModPagespeed off
<Directory "/var/www/html/redmine/public/">
Options -MultiViews
Order allow,deny
Allow from all
AllowOverride none
Satisfy Any
</Directory>
</VirtualHost>

Resources