Nginx rewrite not working (with passenger on Mac OS X)
I have nginx with rewrite working correctly on my server during production.
But when I tried to set the same rule on my local development machine (mac) the rewrite doesn't work.
I want "universitytutor.local" to redirect to "www.universitytutor.local"
Here is the relevant part of my nginx.conf
server{
listen 80;
server_name universitytutor.local;
rewrite ^/(.*) http://www.universitytutor.local/$1 permanent;
}
server {
listen 80;
server_name www.universitytutor.local *.universitytutor.local;
root /Users/barmstrong/NetBeansProjects/universitytutor/public; # <--- be sure to point to 'public'!
passenger_enabled on;
rails_env development;
}
The page loads correctly if I type "universitytutor.local" or "www.universitytutor.local" and does not redirect.
I have * .universitytutor.local because I am using subdomains for different cities, so I need this, but I want the empty subdomain to be redirected to "www".
Any ideas?
0
a source to share
1 answer
Found a solution for this. I was not restarting Nginx correctly, so it was not collecting changes. Doh!
You can reboot like
sudo kill `cat /opt/nginx/logs/nginx.pid `
sudo /opt/nginx/sbin/nginx
or add this to your .bashrc for usability
alias nginx_restart='nginx_stop; nginx_start'
alias nginx_start='sudo /opt/nginx/sbin/nginx'
alias nginx_stop='sudo kill `cat /opt/nginx/logs/nginx.pid `'
0
a source to share