I'm somewhat new to NGINX and as I understand it PHP is handled by using locations, but for every request only one location can be active. If this is the case how can you enable global handling of PHP in complex setups without a lot of duplicate config? Can you not? This example is simple and I understand that this doesn't require much duplicate code, but I'm trying to understand NGINX at a deeper level especially as it gets to rewrites, etc. and my config gets more complex.
1. How do you handle multiple actions that need to be performed on a request such as different doc root and optional PHP.
2. In a related manner, how do you ensure you don't introduce an edge case where PHP files can be downloaded without intending them to be? The downloading PHP issues seems to be particularly troublesome if you add a basic location setting and then fail to realize that folder has PHP files in it.
3. Can you do something like restrict access by IP to a folder without duplicating any PHP handling config into that location? That seems error prone.
Here is an example:
The first location is to handle "virutal" folders. Folders that are inside the current HTTP root, but exist outside the FILE root of the primary site. Some of these folders may have PHP in them. So, I've nested a location. What if this config was more complex? What if I had many disparate virtual folders with many different doc roots. Would I have to create a block like this for each? What if I had a special 404 for PHP files? Would I have to duplicate that config into these blocks? Is there no way at all cascade config options? If I needed to have another "virtual" folder with an IP restriction would I have to set it up complete with a duplicate of the PHP block?
location ~ ^(/resources/|/javascript/|/order/|/sales_template/) {
root /srv/mysite/web/web-main;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#set $full_filename
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param APP_RUNTIME cloud;
fastcgi_param APP_MODE sub_site;
fastcgi_param X-TEST $uri;
fastcgi_param DOCUMENT_ROOT /srv/mysite/web/web-main;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#set $full_filename
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param APP_RUNTIME cloud;
fastcgi_param APP_MODE sub_site;
fastcgi_param X-TEST $uri;
fastcgi_param DOCUMENT_ROOT /srv/mysite/web/web-main;
}
1. How do you handle multiple actions that need to be performed on a request such as different doc root and optional PHP.
2. In a related manner, how do you ensure you don't introduce an edge case where PHP files can be downloaded without intending them to be? The downloading PHP issues seems to be particularly troublesome if you add a basic location setting and then fail to realize that folder has PHP files in it.
3. Can you do something like restrict access by IP to a folder without duplicating any PHP handling config into that location? That seems error prone.
Here is an example:
The first location is to handle "virutal" folders. Folders that are inside the current HTTP root, but exist outside the FILE root of the primary site. Some of these folders may have PHP in them. So, I've nested a location. What if this config was more complex? What if I had many disparate virtual folders with many different doc roots. Would I have to create a block like this for each? What if I had a special 404 for PHP files? Would I have to duplicate that config into these blocks? Is there no way at all cascade config options? If I needed to have another "virtual" folder with an IP restriction would I have to set it up complete with a duplicate of the PHP block?
location ~ ^(/resources/|/javascript/|/order/|/sales_template/) {
root /srv/mysite/web/web-main;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#set $full_filename
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param APP_RUNTIME cloud;
fastcgi_param APP_MODE sub_site;
fastcgi_param X-TEST $uri;
fastcgi_param DOCUMENT_ROOT /srv/mysite/web/web-main;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#set $full_filename
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param APPLICATION_ENV development;
fastcgi_param APP_RUNTIME cloud;
fastcgi_param APP_MODE sub_site;
fastcgi_param X-TEST $uri;
fastcgi_param DOCUMENT_ROOT /srv/mysite/web/web-main;
}