Skip to content

Commit

Permalink
split php upstream settings into its own configuration file and assig…
Browse files Browse the repository at this point in the history
…n to $upstream variable
  • Loading branch information
nerrad committed Oct 23, 2017
1 parent 39093b1 commit edca304
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 28 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions global/php-pool.conf
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 4 additions & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions sites-available/fastcgi-cache.com
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions sites-available/multisite-subdirectory.com
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions sites-available/multisite-subdomain.com
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions sites-available/singlesite.com
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions sites-available/ssl-fastcgi-cache.com
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions sites-available/ssl.com
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,4 +59,4 @@ server {
server_name www.ssl.com;

return 301 https://ssl.com$request_uri;
}
}
4 changes: 4 additions & 0 deletions upstreams/php70.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Defines the upstream for PHP 7.0
upstream php70 {
server unix:/run/php/php7.0-fpm.sock;
}

0 comments on commit edca304

Please sign in to comment.