How to serve using Passenger running with SSL - ruby-on-rails

I have a Rails 4 application and I want to run it on Passenger with SSL.
I added the Passenger gem to the gemfile and ran the server using:
bundle exec rails s -e production -p 3001 --binding=0.0.0.0
In settings I set ssl = true, which works. The SSL is recomended and the server wants to call the app with HTTPS.
When I set the vhost for HTTPS port 443 like this:
ProxyPreserveHost On
ProxyRequests On
ServerName domain.de
ServerAlias *.domain.de
ProxyPass / https://subdomain.domain.de:3001/
ProxyPassReverse / https://subdomain.domain.de:3001/
SSLEngine on
I got this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at domain.de Port 443
The SSL certificate is provied through plesk 12.5.
What's the problem in this case? What do I have to change?

better and much easier way is to use passangermodule for apache or nginx

Related

Deploying Ruby on Rails App using Passenger & Apache

I am trying to deploy my Ruby on Rails application using Phusion Passenger and the Apache2 module on MacOS. I believe I have installed all dependencies and gems correctly and think a problem lies in my configuration files. I do not have a domain so I am trying to use localhost to deploy.
this first file is the configuration for the apache2 web server and is located in /private/etc/apache2/httpd.conf I think my issue is with the ServerName. I do not have a domain to publicly host this web application from yet. I am trying to locally deploy it first. I have been using localhost:3000 for my development and want to deploy it using that as well. Maybe I am not understanding something vital here with deploying and ServerName.
httpd.conf
<VirtualHost *:80>
ServerName localhost.depot
DocumentRoot /Users/rubythree/Documents/agile-web-development-with-rails-5.1/production/depot/public
SetEnv SECRET_KEY_BASE "secret_key_here"
<Directory /Users/rubythree/Documents/agile-web-development-with-rails-5.1/production/depot/public>
AllowOverride all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
the next file where an issue might be is the hosts file located in /private/etc/hosts where I added the following line...
hosts
127.1.1.1 localhost.depot
I am new to Phusion Passenger and Apache and am pretty sure I am missing something in my configuration files here. When i try to access the ip 127.1.1.1 after a while of loading the browser will not be able to reach the server. running curl 127.1.1.1 will not return anything either, it will timeout. Any help or direction is appreciated :)
Even if ServerName does not match - apache will serve the first virtualhost as default.
"This machine" address is 127.0.0.1, also make sure apache is actually running and has no errors in logs

Nginx configuration error while running Rails app and Wordpress blog on same server

I am developing a Ruby on Rails application and meanwhile I am currently using a Wordpress blog that serves as a landing page.
I am using Ruby (2.2.4) on Rails (4.2.6) on an AWS EC2 instance. I'm also using nginx, apache and puma.
The problem I ran into was the following:
* Restarting nginx nginx [fail]
And the logs are the following:
2016/10/25 23:54:53 [emerg] 24676#0: duplicate upstream "php" in /etc/nginx/sites-enabled/defaultsave:148
I have these two upstream configurations that read as follows (/etc/nginx/sites-enabled/default):
upstream puma {
server unix:///home/deploy/apps/APPLICATION_NAME/shared/tmp/sockets/APPLICATION_NAME-puma.sock;
}
and
upstream php {
server unix:/var/run/php5-fpm.sock;
}
Can I have two upstream configurations? How can I solve this issue?
I also tried commenting one of the upstreams and the logs read as follows:
2016/10/26 00:14:22 [emerg] 25249#0: duplicate listen options for 0.0.0.0:80 in /etc/nginx/sites-enabled/default.save:154
Can I listen to the same port and proxy to the correct server having into account the server_name?

Apache Reverse Proxy Unix Socket

I am trying to setup ProxyPass in Apache 2.4.7 using unix sockets to a puma server for a rails application. I keep receiving a 500 Internal Error. When I check the apache logs I receive this message:
No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
This is my proxy config in apache
ProxyPass / unix:///home/rails/rp/tmp/sockets/puma.sock|http://127.0.0.1/
ProxyPassReverse / unix:///home/rails/rp/tmp/sockets/puma.sock|http://127.0.0.1/
If I setup a Proxy Pass on a regular tcp port like this, it works fine.
ProxyPass / http://127.0.0.1:9292
ProxyPassReverse / http://127.0.0.1:9292
Any help is appreciated, let me know if you need anymore information.
In general, there is some point for checking for reverse proxy an http server app over unix socket:
Check if Apache already loaded required modules (proxy & http_proxy) using apachectl -M command
Make sure that socket path is accessible for www-data user (it is default apache user)
Check correctness of running app on unix socket using following command:
curl --unix-socket /var/www/app/socket/path -XGET http:/someMethod
Check that ProxyPreserveHost On already present in your virtual host file and set socket address correctly (as unix:/var/www/path/to/your/socket) and after pipe mark path correctly (as |http://127.0.0.1/what/ever)
Make sure both ProxyPassReverse and ProxyPass is set correctly
I am not sure which proxy handler should handle sockets, so you could try loading them all then see which one does the job for you:
https://httpd.apache.org/docs/trunk/mod/mod_proxy.html
Note that you can also use SetHandler to specify the module you want to handle your connections
Ok, I spent a while to find the solution on one of my old server.
When you have this mod_proxy error, it's because Apache doesn't recognize the proxy module to use behind the unix socket.
Assuming that you obviously already have :
a2enmod proxy
a2enmod proxy_http
service apache2 restart
There's a good chance that your apache config file located at /etc/apache2/mods-available/proxy_http.load is empty
Add theses lines to this file :
# Depends: proxy
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
then
service apache2 restart

Rails Cloud Server - Installed NGINX but rails app still uses WEBrick

So I've bought and set up my DigitalOcean Ubuntu 14.04 Droplet, set up SSH keys, bought a domain name, transfered my app to the DigitalOcean cloud server using Filezilla and install Passenger with NGINX. It took a lot of trial, error and research but I've learned a lot from it.
The problem is, I still can't get the it to work! When I start my $rails s -e production in the cloud, I noticed it still uses Webrick despite already installing NGINX. I also get a 500 Internal Service Error from NGINX when I visit my website's IP address.
Its likely that I did something wrong, but due to my inexperience, I have no way of really knowing what procedure was incorrect/skipped. Maybe something with Capistrano? my secret keys still need some work done, not sure :/
Can someone help me out?
My checklist:
Install Ruby and Rails and bundle install in my Cloud Server [done]
Install NGINX and Passenger following the tutorial at: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04 [done]
Edited my NGINX config file to:
server {
listen 80 default_server;
server_name 45.55.136.43;
passenger_enabled on;
passenger_app_env production;
root /origins/public;
}

Redirect example.com to rails server running on localhost:3000 leaving apache sites intact?

I am working on a rails app which runs on localhost:3000. I want example.com to point to localhost:3000. I edited the /etc/hosts file but it doesn't take port number so the request goes to apache. I want apache sites to work as they are but redirect example.com to rails server.
Please suggest the best way to achieve this.
Can you just specify example.com:3000 when browsing to your site? If not, I'd suggest using Phusion Passenger so that Apache can continue to respond on port 80 while also running your app.
Use mod_proxy?
ProxyPass /your_rails_app http://your.server.address:3000
ProxyPassReverse /your_rails_app http://your.server.address:3000
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Resources