I have an nginx server with passenger that I am trying to run a ruby on rails app. I am using rbenv and am deploying using capistrano.
I keep getting an error message that is as follows:
directory index of "[/srv/[directory]]" is forbidden, client: [my client ip], server: [my domain], request: "GET / HTTP/1.1", host: "[my domain]"
My nginx config for the site:
server {
listen 80;
server_name [my domain];
passenger_enabled on;
rails_env production;
root /srv/[my app name]/current/public;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
passenger_enabled on;
}
location / {
passenger_enabled on;
}
}
And my config for passenger in my nginx.conf file is as follows:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deploy/.rbenv/shims/ruby;
Related
I have a site that I built using ruby on rails on nginx server with passenger. My client decided to install ssl certificate.I am a newbie to that kind of issues and I have never did it before and I need to confirm that my sites-enabled/default file is configured properly.
My current configuration is :
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name www.mysite.com;
passenger_enabled on;
rails_env production;
root /home/directory;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
and for adding ssl certificate, I will add another server block like below:
server {
listen 443;
server_name www.mysite.com;
passenger_enabled on;
rails_env production;
root /home/directory;
ssl on;
ssl_certificate /etc/ssl/my_certificate;
ssl_certificate_key /etc/ssl/my_private_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_stapling on
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
is that a right way and parameters to configure nginx or I need to combine them in one server block ?
is there any thing missing should I add to the previous config ?
in the :server_name www.mysite.com;
can I replace it with my IP address instead of the domain name ?
Thanks for your time in advance
You can have HTTP and HTTPS servers in the same server section
server {
listen 80;
listen [::]:80 ipv6only=on;
listen 443 ssl;
...
}
For complete SSL related configuration I would recommend to use Mozilla generator
Yes, but you shouldn't. Nginx will match your first server section even if you haven't set server_name properly, but such configuration is hard to support and troubleshoot
I have install Nginx and Passenger using How To Deploy a Rails App with Passenger and Nginx. I did everything as per the blog. But when I reload Nginx service sudo nginx -s reload it is showing nginx: [warn] conflicting server name "ip_address" on 0.0.0.0:80, ignored
/etc/site-available/default
server {
#listen 80;
#listen [::]:80 ipv6only=on;
server_name ip_address;
passenger_enabled on;
rails_env production;
root /var/www/testapp/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
/etc/site-available/testapp
server {
listen 80 default_server;
server_name ipaddress;
passenger_enabled on;
passenger_app_env development;
root /home/iradmin/rails_project/testapp/public;
}
I don't know what I have done wrong in here. Thanks in advance.
In your /etc/sites-available/default config you have set server_name to ipaddress and in /etc/sites-available/testapp you have also given a server_name of ipaddress.
The error message states that you have a conflict because in both files - the server name is ipaddress. To resolve this error, give your servers different names. More information on Nginx server_name can be found in the official docs here.
I need help with my nginx configuration.
I want to run a rails app and a Wordpress blog under the same domain.
Wordpress should be available under a subfolder/path.
Both are already up and running, but I cannot access blog posts.
Here is my current configuration:
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name my-secret-host.com;
passenger_enabled on;
passenger_min_instances 1;
rails_env production;
root /var/www/rails-app/current/public;
# Wordpress
location /news {
alias /var/www/wordpress/;
index index.php ;
try_files $uri $uri/ /index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
I tried a lot.
With this variation the Rails app works as expected. Wordpress is also up and running, the admin area and the index page (/) are available.
But if I call a permalink to a post like http://my-secret-host.com/news/2017/10/permalink-test-post/ the rails app responds with an error.
Maybe the solution is stupid and simple, but all my attempts ended in other problems and errors.
Moving the rails config into a location / block didn't change anything.
With disabled rails configuration I get another error, the path to index.php is not properly configured.
[error] 7705#7705: *7 open() "/usr/share/nginx/html/index.php" failed (2: No such file or directory), client: 87.133.34.209, server: my-host.com, request: "GET /news/2017/10/test234/ HTTP/1.1", host: "my-host.com", referrer: "http://my-host.com/news/"
What you see above is a activated/linked configuration file in nginx/sites-available/.
I unlinked sites-available/default, created my own and didn't change anything in nginx.conf– expect of the rails-passenger include.
I have the following problem with passenger
Permission denied # rb_sysopen
I have only root user in server and install all with root user.
Config Passenger
server {
listen 80;
server_name localhost;
passenger_enabled on;
passenger_app_env testing;
passenger_user root;
passenger_group root;
root /opt/my_app/public;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Passenger Version 5.1.8
Thanks for your time!!
xD
I have an issue with my rails application running with passenger and nginx hosted in Ubuntu 12.04.
In the nginx.conf file below, my "example.com" (Regular HTML) and "redmine.example.com" (Rails app) are working perfectly, but my "crete.example.com" (Another Rails app) is showing "502 bad gateway". I have them both hosted in /var/data with the same permissions and ownerships, also tried different ports, I can't think of something else to try.
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server{
listen 80;
server_name example.com;
root /opt/nginx/html;
}
server{
server_name redmine.example.com;
root /var/data/redmine/public;
passenger_enabled on;
location ~ ^/<SUBURI>(/.*|$){
alias /var/data/redmine/public$1;
passenger_base_uri /redmine;
passenger_app_root /var/data/redmine;
passenger_document_root /var/data/redmine/public;
passenger_enabled on;}
}
server{
server_name crete.example.com;
root /var/data/crete/public;
passenger_enabled on;
location ~ ^/<SUBURI>(/.*|$){
alias /var/data/crete/public$1;
passenger_base_uri /crete;
passenger_app_root /var/data/crete;
passenger_document_root /var/data/crete/public;
passenger_enabled on;}
}
}
This are my Ruby and Rails versions:
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
Rails 4.1.0
My nginx error.log
2014/05/02 12:29:50 [error] 3343#0: *4 upstream prematurely closed connection while reading response header from upstream, client: xxx.xx.xx.xx, server: crete.example.com, request: "GET / HTTP/1.1", upstream: "passenger:/tmp/passenger.1.0.3
323/generation-0/request:", host: "crete.example.com"
Any other conf file you might need to solve this don't hesitate to ask.
Check out your sites-available and sites-enabled and see if your other rails app is included and configured properly. Also, check if these files are included in your nginx.conf