Merge pull request #13 from nerrad/fet/php-upstream

Fet/php upstream
This commit is contained in:
Ashley Rich 2017-11-26 16:12:15 +00:00 committed by GitHub
commit c633ab9081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 74 additions and 41 deletions

View File

@ -13,6 +13,26 @@ Looking for a modern hosting environment provisioned using Ansible? Check out [W
## Usage ## 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. 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: 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; include global/limits.conf;
# Some WP plugins that push large amounts of data via cookies # 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_buffers 16 16k;
fastcgi_buffer_size 32k; fastcgi_buffer_size 32k;
@ -44,6 +44,9 @@ http {
# Gzip # Gzip
include global/gzip.conf; include global/gzip.conf;
# exposes configured php pool on $upstream variable
include global/php-pool.conf;
# Modules # Modules
include /etc/nginx/conf.d/*.conf; include /etc/nginx/conf.d/*.conf;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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;
}