views:

759

answers:

1

I have nginx with rewriting working correctly on my server in production.

But when I tried to set the same rule on my local development machine (mac) the rewrite doesn't seem to be working.

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 whether I type "universitytutor.local" or "www.universitytutor.local" and it does not redirect.

I have the *.universitytutor.local in there because I use subdomains for different cities so I need this, but I want a blank subdomain to redirect to "www".

Any ideas?

A: 

Found the solution for this. I was not restarting Nginx correctly so it was not picking up the changes. Doh!

You can restart like this

sudo kill `cat /opt/nginx/logs/nginx.pid `
sudo /opt/nginx/sbin/nginx

or add this to your .bashrc for easier use

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 `'
Brian Armstrong
I find it easier (on linux anyway) to do a sudo /opt/nginx/sbin/nginx -s stop instead of the kill.
Frozenskys
Or "service nginx reload/stop/start"?
Cimm