简体   繁体   中英

nginx rewrite not working (with passenger on Mac OS X)

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?

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 `'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM