1
I’m having trouble setting up Nginx as a reverse proxy in an application. It’s a Rails application that runs on Unicorn.
In case, I have the mastery http://www.meudominio.com.br. Instead of creating a subdomain, I would like http://www.meudominio.com.br/meuprojeto/ was the root url and directed the requests to my application. Looking in the English OS I saw some possible solutions. I tested some, and following the one that came closest to working, my configuration file got like this:
upstream meuprojeto {
server unix:/var/www/apps/meuprojeto/shared/tmp/sockets/meuprojeto.sock;
}
server {
listen 80;
server_name meuprojeto.com.br max_fails=0;
index index.html;
root /var/www/apps/meu_projeto/current/public;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
error_log /var/log/nginx/meu_projeto.log debug;
location /meuprojeto {
rewrite ^/meuprojeto/(.*)$ /$1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://meuprojeto/;
}
}
With this configuration, when access http://www.meudominio.com.br/meuprojeto , the request is correctly directed to the home of my application, but all links stop working, since the generated url’s are like http://www.meudominio.com.br/sobre ,when they should be something like http://meudominio.com.br/meuprojeto/sobre. What to do to make it work? The configuration is in Nginx or should be done in Rails?
there is some reason to use rewrite, it would not be better to use the "Passenger"?
– Guilherme Nascimento
I don’t really understand these settings of Nginx... I used rewrite because I saw an answer from the English OS.
– Pedro Vinícius
Yes, normal... but what I want to know is if you want to use rewrite for some reason, like customization, or you followed some tutorial that indicated this, because the answer I have in mind would not be using rewrite. Is using Linux?
– Guilherme Nascimento
I followed an answer that indicated this. There is no reason to use it. Yes, Ubuntu Server + Nginx + Unicorn.
– Pedro Vinícius
I added an answer, if you fail let me know, because I will try to put a step by step complete!
– Guilherme Nascimento