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 can't access PHP files placed in sub-directories and my CSS/JS files return a 404 in browser. Yes, I have seen many others experiencing a 404 issue but their fixes don't seem to be my solution. I've also swapped out my configuration with several online. Here is my configuration:

server {

    # Port that the web server will listen on.
    listen          80;

    # Host that will serve this project.
    server_name     .stackoverflow.com;

    # Useful logs for debug.
    access_log      /var/log/nginx/access.log;
    error_log       /var/log/nginx/error.log;
    rewrite_log     on;

    # The location of our projects public directory.
    root            /usr/share/nginx/html/public;

    # Point index to the Laravel front controller.
    index           index.php;

    location / {

        # URLs to attempt, including pretty ones.
        try_files   $uri $uri/ /index.php?$query_string;

    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
        rewrite     ^/(.+)/$ /$1 permanent;
    }

    # PHP FPM configuration.
    location ~* \.php$ {
            fastcgi_pass                    unix:/var/run/php5-fpm.sock;
            fastcgi_index                   index.php;
            fastcgi_split_path_info         ^(.+\.php)(.*)$;
            include                         /etc/nginx/fastcgi_params;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # We don't need .ht files with nginx.
    location ~ /\.ht {
            deny all;
    }

    # Set header expirations on per-project basis
    location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
            expires 365d;

    }
}

Is there something wrong with my configuration? Thank you in advance.

share|improve this question
    
Where are the files? What is in the error log? –  Michael Hampton Jul 8 at 21:30
    
Your location ~ \.ht rule prevents access to all files that contain the string .ht in their filenames. For example, it denies access to all .html files. I think you mean location ~ ^\.ht there, which prevents access to all files starting with .ht. –  Tero Kilkanen Jul 9 at 6:59

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.