Friday, October 11, 2019

ubuntu - Nginx gives 404 error for rails app except the root

I have an Ubuntu 12.04 LTS VPS server that serves a static website with Nginx. I would like to set up a rails application that is accesible from the subfolder 'foo'. I use Passenger for serving the rails app



That is how I configured Nginx:




worker_processes  1;

events {
worker_connections 1024;
}

http {
passenger_root /home/akarki/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.5;
passenger_ruby /home/akarki/.rvm/wrappers/ruby-1.9.3-p429/ruby;


server_names_hash_bucket_size 64;

include mime.types;
default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;
gzip on;

gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
charset UTF-8;
error_log /opt/nginx/logs/file.log warn;

server {
listen 80;
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}


server {
listen 80;
server_name domain.com;
index index.html index.htm;
root /srv/www/domain.com;
passenger_enabled on;
passenger_base_uri /foo;
try_files $uri.htm $uri.html $uri/ =404;


location = / {
rewrite ^ /de permanent;
}

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

}


The static website works as expected but the only URL of the rails app that is accessible is the root under 'http://domain.com/foo'



Any other url gives a 404 error.



Do you have any suggestion how to fix this?

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...