Thin server behind apache, stops working when I update code - ruby-on-rails

I've got a rails app on a thin server as a Windows service that is proxied through Apache server. The app works correctly until I try to upload a new version of the project. Then I get a 502 bad gateway error. I tried restarting all of the services but no luck. It also looks like I can't hit it on port 3000 locally. Here's my apache httpd excerpt:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
ServerName serverName
DocumentRoot "C:/locationOfAppDir"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On
</VirtualHost>
<VirtualHost serverName>
ServerName serverName
DocumentRoot "C:/locationOfAppDir"
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
ProxyPreserveHost On
</VirtualHost>

Protip to self: run bundle install when you add updated code with new gems.

Related

nextjs in docker proxy via apache2 is giving 502 proxy errors

I have a nextjs application running in a docker. When I had the same docker image running locally and goto localhost:3000 everything runs perfectly.
I then deploy the image to the server and I have apache2 proxy passing to the site I get a broken landing page
I see I am getting errors like this
Request URL: http://example.com/_next/static/css/175964cd052c7c3f.css
Request Method: GET
Status Code: 502 Proxy Error
My apache setup is like this
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia On
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:3000 connectiontimeout=6000 timeout=6000
ProxyPassReverse / http://127.0.0.1:3000
CustomLog /var/log/apache2/mydomain.access.log combined
ErrorLog /var/log/apache2/mydomain.error.log
</VirtualHost>
Any help would be appreciated
Thanks
<VirtualHost *:80>
ServerName www.myservername.com
ServerAlias myservername.com
ErrorLog /var/www/myapp/log/error.log
CustomLog /var/www/myapp/log/requests.log combined
ProxyRequests on
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
It seems something was clashing. When I stripped it down to the above it works

apache bad request with 443 and reverse proxy

I have 2 docker containers, 1 running apache2 and 1 running a python api.
In non-https, I was able to make the connection such that requests on 80 are channeled to the docker container running the python api. When I enable HTTPS, requests come in as 400 (bad request).
Any help greatly appreciated. This is my virtual host file.
<VirtualHost *:443>
ServerName domain.com
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://172.17.0.1:8000/
ProxyPassReverse / http://172.17.0.1:8000/
SSLEngine on
SSLCertificateFile "/usr/local/apache2/conf/.crt"
SSLCertificateKeyFile "/usr/local/apache2/conf/.key"
</VirtualHost>
Apache logs should contain a more detailed error, however based on the configuration you posted, I would check if "/usr/local/apache2/conf/.crt" and "/usr/local/apache2/conf/.key" exists.

Proxy Pass Subdirectory in Apache Passenger with Rails App

I have a rails app (www.myapp.com) for which I am using Apache Passenger. The virtual host is configured as follows:
<VirtualHost *:80>
DocumentRoot "/var/www/myapp/current/public"
RailsEnv production
<directory "/var/www/myapp/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</directory>
RailsBaseURI /
</VirtualHost>
I have a blog which is hosted externally on some other domain, lets say www.myapp-blog.com. I want to 301 redirect any requests to www.myapp.com/blog or www.myapp.com/blog/* to the relevant pages on www.myapp-blog.com. Everything else should flow through my Rails app.
How should I modify the above virtual host configuration to achieve this?
use apache port forwarding technique...
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.myapp-blog.com
ServerAlias myapp-blog.com
ProxyPass / http://www.myapp.com/blog/
ProxyPassReverse / http://www.myapp.com/blog
</VirtualHost>

Directory index forbidden by Options directive in ruby on rails

I Configured SSL for rails app running with thin server in CentOS linux environment with apache. When I try to open my site using "https" I am getting Apache error page and I checked apache error logs and got the following error message
Directory index forbidden by Options directive.
I made some changes in /etc/httpd/conf.d/welcome.conf as
"Options -Indexes" TO "Options +Indexes"
then I am getting directory structure in browser.
Please help me to solve the issue
Update:
<VirtualHost *:80>
ServerName XXXX
ServerAlias www.XXXX.com
DocumentRoot XXXX
RewriteEngine On
<Proxy balancer://thinservers>
BalancerMember http://127.0.0.1:3000
</Proxy>
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]
ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog XXXX
CustomLog XXXX
Your included Apache configuration shows the HTTP virtual host as it's litening on port 80
<VirtualHost *:80>
HTTPS connects to a different virtual host defined on port 443 you will need to modify this virtualhost's configuration in order to change the way the HTTPS portion of your website behaves.

Share Rails 3 Phusion Passenger Deployment Between HTTP and HTTPS

I have an apache virtual host for port 80 that hosts a rails 3 phusion passenger application. I would like some actions of the application to switch to https (port 443). What is the best way to share one instance of a phusion passenger rails application between two vhosts?
Right now, I have:
<VirtualHost *:80>
ServerName mycompany.com
ServerAlias www.mycompany.com
RackBaseURI /
DocumentRoot /home/ubuntu/mycompany/public
<Directory /home/ubuntu/mycompany/public >
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and
<VirtualHost _default_:443>
ServerName shop.mycompany.com
SSLEngine On
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
ProxyPreserveHost On
SSLCertificateFile /etc/ssl/...
SSLCertificateKeyFile /etc/ssl/...
SSLCertificateChainFile /etc/ssl/...
</VirtualHost>
I know this is not ideal at all. There must be a better way. I do not want all requests to go through https due to the overhead.
Mike

Resources