Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm migrating from mod_php to nginx. I got everything working except for this rewrite.. I'm just not familiar enough with nginx configuration to know the correct way to do this.

I came up with this by looking at a sample on the nginx site.

server {
    server_name test01.www.myhost.com;
    root /home/vhosts/my_home/blah;

    access_log /var/log/nginx/blah.access.log;
    error_log /var/log/nginx/blah.error.log;

    index index.php;

    location / {
            try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
            rewrite ^ /index.php last;
            rewrite ^/ht/userGreeting.php /js/iFrame/index.php last;
            rewrite ^/ht/(.*)$ /$1 last;
            rewrite ^/userGreeting.php$ /js/iFrame/index.php last;
            rewrite ^/a$ /adminLogin.php last;
            rewrite ^/boom\/(.*)$ /boom/index.php?q=$1 last;
            rewrite ^favicon.ico$ favico_ry.ico last;

    }

    # This block will catch static file requests, such as images, css, js
    # The ?: prefix is a 'non-capturing' mark, meaning we do not require
    # the pattern to be captured into $1 which should help improve performance
    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    include php.conf;
    }

The issue I'm having is with this rewrite:

rewrite ^ht\/(.*)$ /$1 last;

99% of requests that will hit this rewrite are static files. So I think maybe it's getting sent to the static files section and that's where things are being messed up?

I tried adding this but it didn't work:

    location ~* ^ht\/.*\.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

Any help would be appreciated. I know the best thing to do would be to just change the references of /ht/whatever.jpg to /whatever.jpg in the code.. but that's not an option for now.

share|improve this question
    
It seems to not even be getting to the rewrites. I think my problem is with try_files –  skrewler Apr 4 '12 at 21:37

2 Answers 2

Try this: location ~ ((ht/.*)|(?:ico|css|js|gif|jpe?g|png)$)

share|improve this answer
up vote 0 down vote accepted

I fixed the issue by adding

try_files $uri $uri/ @rewrites;

to the static files location block.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.