Nginx runs all php files except index.php

So, on my server, I have an info.php file that I can work fine and all readings look good. I can also run several other files, no questions. Buuuuut, index.php is sent to me as a file containing all the PHP source code, which is very bad. At the top of this transition to the base page, not a single file is supported at all, especially index.php.

Here is my nginx configuration:

server {
        server_name somedamnserver;
        root /var/www;
        index index.php index.html;

        location / {
                # This is cool because no php is touched for static content
                try_files $uri $uri/ /index.php;
        }

        location ~ \.php$ {
                #fastcgi_split_path_info ^(.+\.php)(/.+)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_intercept_errors on;
                include fastcgi_params;
        }
}

My php.ini and fpm / pool.d / www.conf files are configured correctly, but I can also link them here.

I am here on my way, I just can’t understand why this server bully will do this a little for me. :(

+3
source share
2 answers

, , . , PHP, , , php5-json php5-mysql ( , ), mysql, , -, 127.0. 0.1 localhost - .

-, , , , 500 .

, , .

Update: , . , , , . , . gzipping , , .

server {
        server_name somedamnserver;
        root /var/www;
        rewrite_log on;

        gzip_static on;
        # This is file type association solution 1
        # location ~ \.css {
            # add_header  Content-Type    text/css;
        # }
        # location ~ \.js {
            # add_header  Content-Type    application/x-javascript;
        # }
        # This is file type association solution 2
        location ~* ^[^\?\&]+\.(html|jpg|jpeg|json|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|svg|woff|ttf)$ {
            try_files $uri /index.php?file=$1;
            #access_log off;
            expires 24h;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }
        # This will make PHP files run as intended, I have uncommented a few options as I do not need them.
        location  / {
            #set $originalURI  $uri;
            try_files $uri /index.php /50x_static.html;
            #fastcgi_param  QUERY_STRING  q=$originalURI&$query_string;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            #fastcgi_intercept_errors on;
            include fastcgi_params;
        }
}
0

.

-, try_files $uri $uri/ /index.php;, index.php , nginx .

-, /, /index.php, - .

, . , . PHP. .

location ~* ^[^\?\&]+\.(html|jpg|jpeg|json|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|svg|woff|ttf)$ {
    try_files $uri /index.php?file=$1;

    #access_log off;
    expires 24h;
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}


location  / {
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
            set $originalURI  $uri;
            try_files $uri /index.php /50x_static.html;
            fastcgi_param  QUERY_STRING  q=$originalURI&$query_string;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            #fastcgi_intercept_errors on;
            include fastcgi_params;
 } 

, , .

btw rewrite_log on; , .

+1

All Articles