1

Still pretty new to nginx here, trying to get a simple rewrite to work, but the server just responds '404 not found'

My server block

server {
listen   80;
listen   [::]:80;

server_name pics.example.com;
root /home/pics;

rewrite ^(.*)$ index.php?tag=$1;

location / {

    try_files $uri $uri/ $uri.php /index.html $uri =404;
    #try_files $uri =404;

    fastcgi_split_path_info ^([a-z]+)(/.+)$;
    include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
}

location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    allow 127.0.0.1;
    deny all;
}
}

pics.example.com/foobear should rewrite to pics.example.com/index.php?tag=foobear

1 Answer 1

2

Remove the rewrite and replace the try_files line with the following:

try_files $uri $uri/ /index.php?tag=$uri&$args;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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