I have Cockpit CMS installed and with this conf file, every real folders where I have files or subwebsites that I want to share or access are interpreted as 404 pages, I guess because of this part :

location / {
    try_files $uri /index.php$uri?$args;

Then I need to specify every link and folders to enable access. This is kinda constraining. Do you have an idea to avoid this?

server {
    listen 443 ssl;
    server_name site.com;
    root /var/sites/_site.com/www;

    index index.php index.html;

    location / {
        try_files $uri /index.php$uri?$args;

    location /cockpit {
        try_files $uri $uri/ /cockpit/index.php;

    # Enable PHP with path_info
    location ~ ^(.+\.php)($|/) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;

    # Files index
    location /files { autoindex on; }
    location /specific-link {}
    location /specific-folder {}

Maybe this syntax variation will help you?

 try_files $uri $uri/ /index.php$uri?$args;

This tries folders as well as files before passing it on to the backend if they don't physically exist.

  • this actually works for any folder/link, but now my homepage returns a 404…! any thought? – flks Feb 3 '16 at 0:30
  • Try adding an if or additional location block to special-case the homepage. – Mark Stosberg Feb 3 '16 at 1:01
  • thank you! works like a charm with this additionnal rule: location = / { try_files $uri /index.php$uri?$args; } – flks Feb 3 '16 at 10:57

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.