split php upstream settings into its own configuration file and assign to $upstream variable

This commit is contained in:
Darren Ethier 2017-10-22 20:15:00 -04:00
parent 39093b1486
commit edca3040eb
10 changed files with 61 additions and 28 deletions

View File

@ -13,6 +13,26 @@ Looking for a modern hosting environment provisioned using Ansible? Check out [W
## Usage
### PHP configuration
The php-fpm pool configuration is located in `global/php-pool.conf` and defaults to PHP 7.1. It will need modified if you want the default php-fpm pool service to be a different PHP version. Additional PHP version upstream definitions can be added to the `/upstreams` folder (a PHP 7.0 sample is provided there). You can either use the default pool using `$upstream` in your nginx configurations or the specific upstream definition (i.e. php71, php70) setup by your custom upstream definitions.
For example, currently the nginx configuration for `singlesite.com` has the following set for php requests:
```
fastcgi_pass $upstream
```
You could change that to the following to use the php 7.0 php service instead (assuming that php7.0-fpm service is running).
```
fastcgi_pass php70
```
This effectively allows you to have different server blocks execute different versions of PHP if needed.
### Site configuration
You can use these sample configurations as reference or directly by replacing your existing nginx directory. Follow the steps below to replace your existing nginx configuration.
Backup any existing config:

12
global/php-pool.conf Normal file
View File

@ -0,0 +1,12 @@
# Upstream to abstract backend connection(s) for PHP.
# Additional upstreams can be added to /etc/nginx/upstreams/*.conf and then you just
# change `default php71` to whatever the new upstream is (could be php70 for example).
upstream php71 {
server unix:/run/php/php7.1-fpm.sock;
}
include /etc/nginx/upstreams/*.conf;
map '' $upstream {
default php71;
}

View File

@ -33,7 +33,7 @@ http {
include global/limits.conf;
# Some WP plugins that push large amounts of data via cookies
# can cause 500 HTTP erros if these values aren't increased.
# can cause 500 HTTP errors if these values aren't increased.
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
@ -44,6 +44,9 @@ http {
# Gzip
include global/gzip.conf;
# exposes configured php pool on $upstream variable
include global/php-pool.conf;
# Modules
include /etc/nginx/conf.d/*.conf;

View File

@ -35,10 +35,9 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
# Skip cache based on rules in global/server/fastcgi-cache.conf.
fastcgi_cache_bypass $skip_cache;

View File

@ -30,10 +30,9 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
}
# Rewrite robots.txt

View File

@ -27,10 +27,9 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
}
# Rewrite robots.txt

View File

@ -27,10 +27,9 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
}
# Rewrite robots.txt

View File

@ -42,10 +42,9 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
# Skip cache based on rules in global/server/fastcgi-cache.conf.
fastcgi_cache_bypass $skip_cache;

View File

@ -34,14 +34,13 @@ server {
try_files $uri =404;
include global/fastcgi-params.conf;
# Change socket if using PHP pools or different PHP version
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# Use the php pool defined in the upstream variable.
# See global/php-pool.conf for definition.
fastcgi_pass $upstream;
}
# Rewrite robots.txt
rewrite ^/robots.txt$ /index.php last;
# Rewrite robots.txt
rewrite ^/robots.txt$ /index.php last;
}
# Redirect http to https

4
upstreams/php70.conf Normal file
View File

@ -0,0 +1,4 @@
# Defines the upstream for PHP 7.0
upstream php70 {
server unix:/run/php/php7.0-fpm.sock;
}