0

I have the next config for nginx, url /website/blog/index.php works but url /website/blog/ doesn't works

server {
    listen 80;
    root /var/www/site;
    index index.html index.htm index.php;
    server_name site.com;

    rewrite_log on

    #IMPORTANT
    location ~ /.*(\.py|\.ini)$ {
        deny all;
    }

    location ^~ /website/blog/ {
        rewrite ^.*$ /website/blog/index.php$request_filename last;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
0

Per your comment this actually looks like it could be basic syntax issues. In future, I would strong suggest running nginx -t (without sudo) to display configuration errors.


I think a try-files is preferred over a rewrite but either way, here's what I use for a Moodle site.

    location / {
            try_files $uri $uri/ /index.php/$request_uri;
    }

    location ~ .php($|/) {
            set $script $uri;
            if ($uri ~ "^(.+.php)(/.+)") {
                    set $script $1;
            }
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_index index.php;

            include fastcgi.conf;

            fastcgi_param SCRIPT_FILENAME $document_root$script;
            fastcgi_temp_file_write_size 10m;
            fastcgi_busy_buffers_size 512k;
            fastcgi_buffer_size 512k;
            fastcgi_buffers 16 512k;
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_intercept_errors on;
            fastcgi_next_upstream error invalid_header timeout http_500;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

Unfortunately the exact rewriting rules requires seems to change subtly for each engine, but nginx is popular enough that Googling nginx url <<engine, eg wordpress>> will get you some suggestions.

  • The problem was that I forget a ; after rewrite_log on – Adrian B Jan 22 '15 at 8:21
  • And after include fastcgi_params. – Oli Jan 22 '15 at 8:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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