Config for serving website on nginx server via sub url Config for serving website on nginx server via sub url nginx nginx

Config for serving website on nginx server via sub url


Most likely reason for the php files being downloaded because the php handling location block in nested under another location block (This assumes php has been correctly setup).

Overall, your config seems overly complicated and I am sure whatever task it is doing can be done with a far more straightforward configuration.

I have done a basic clean up / consolidation but not having a full picture, some bits may be off. Should give you some ideas though.

Important thing though regarding the PHP is pulling it out of the nested location.

Also, using Status Code 418 instead of 405 for redirection as 405 can be legitimately generated for other reasons.

Using a separate server block for the example.com to www.example.com redirection for better performance.

server {    listen my.ip:80;    server_name example.com;    rewrite ^ http://www.example.com$request_uri? permanent;}server {    listen my.ip:80;    server_name www.example.com;    root /var/www/example;    index index.php index.html;    error_page 418 = @nocache;    if ($query_string ~ ".+") {        return 418;    }    # pass requests from logged-in users to PHP    if ($http_cookie = 'nc_staticfilecache|be_typo_user' ) {        return 418;    }     # pass POST requests to PHP    if ($request_method !~ ^(GET|HEAD)$ ) {        return 418;    }    location = /partner/robots.txt {        allow all;        log_not_found off;        access_log off;    }    location ^~ /partner/typo3temp/tx_ncstaticfilecache {        expires 43200;        charset utf-8;    }    location = /partner/clear.gif {        empty_gif;        expires max;    }    location ^~ /partner/typo3/gfx {        expires max;    }    location ^~ /partner/typo3temp/compressor {        expires max;    }    location /partner {        # serve requested content from the cache if available,         # otherwise pass the request to PHP        try_files /typo3temp/tx_ncstaticfilecache/$host${request_uri}index.html @nocache;    }    location ~* \.(sql|tpl|html5|xhtml) {        deny all;    }    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)(.*)$ {        expires max;        log_not_found off;    }    location ~ /\. {        deny all;        access_log off;        log_not_found off;    }    location ~ \.php$ {        return 418;    }    location @nocache {        try_files $uri =404;        include /etc/nginx/fastcgi_params;        fastcgi_pass 127.0.0.1:9000;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        fastcgi_index index.php;                }}