Skip to content

Commit

Permalink
Merge pull request #18 from devilbox/release-0.23
Browse files Browse the repository at this point in the history
Ensure PHP-FPM works exactly as for Apache on main vhost
  • Loading branch information
cytopia authored Dec 18, 2018
2 parents e2e3580 + b5fd61c commit 018bea9
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 3 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ RUN set -x \
###
COPY ./data/vhost-gen/main.yml /etc/vhost-gen/main.yml
COPY ./data/vhost-gen/mass.yml /etc/vhost-gen/mass.yml
COPY ./data/vhost-gen/templates-main /etc/vhost-gen/templates-main
COPY ./data/create-vhost.sh /usr/local/bin/create-vhost.sh
COPY ./data/docker-entrypoint.d /docker-entrypoint.d
COPY ./data/docker-entrypoint.sh /docker-entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ test:
.ci/start-ci.sh $(image) $(ARG)

pull:
docker pull $(shell grep FROM Dockerfile | sed 's/^FROM//g'; done)
docker pull $(shell grep 'FROM' Dockerfile | sed 's/^FROM//g'; )
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,5 @@ It allows any of the following combinations:
## Version

```
nginx version: nginx/1.14.0
nginx version: nginx/1.14.2
```
4 changes: 3 additions & 1 deletion data/docker-entrypoint.d/07-vhost-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ vhost_gen_generate_main_vhost() {
else
verbose=""
fi
run "vhost_gen.py -n localhost -p ${docroot} -c ${config} -o ${template} ${verbose} -d -s -m ${ssl_type}" "${debug}"
# Adding custom nginx vhost template to ensure paths like:
# /vendor/index.php/arg1/arg2 will also work (just like Apache)
run "vhost_gen.py -n localhost -p ${docroot} -t /etc/vhost-gen/templates-main/ -c ${config} -o ${template} ${verbose} -d -s -m ${ssl_type}" "${debug}"
fi
}

Expand Down
Empty file.
Empty file.
173 changes: 173 additions & 0 deletions data/vhost-gen/templates-main/nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
---

#
# Slightly modified version of the nginx template for mass vhost
# This mitigates the following issue:
# https://www.reddit.com/r/nginx/comments/a6pw31/phpfpm_does_not_handle_subpathindexphparg1arg2/
#
# Search this file for 'CHANGED:'
#


# Nginx vHost Template defintion for vhost-gen.py
#
# The 'feature' section contains optional features that can be enabled via
# conf.yml and will then be replaced into the main vhost ('structure' section)
# into their corresponding position:
#
# __XDOMAIN_REQ__
# __PHP_FPM__
# __ALIASES__
# __DENIES__
# __STATUS__
#
# The features itself also contain variables to be adjusted in conf.yml
# and will then be replaced in their corresponding feature section
# before being replaced into the vhost section (if enabled):
#
# PHP-FPM:
# __PHP_ADDR__
# __PHP_PORT__
# XDomain:
# __REGEX__
# Alias:
# __REGEX__
# __PATH__
# Deny:
# __REGEX__
# Status:
# __REGEX__
#
# Variables to be replaced directly in the vhost configuration can also be set
# in conf.yml and include:
# __VHOST_NAME__
# __DOCUMENT_ROOT__
# __INDEX__
# __ACCESS_LOG__
# __ERROR_LOG__
# __PHP_ADDR__
# __PHP_PORT__
#


###
### Basic vHost skeleton
###
vhost: |
server {
listen __PORT____DEFAULT_VHOST__;
server_name __VHOST_NAME__;
access_log "__ACCESS_LOG__" combined;
error_log "__ERROR_LOG__" warn;
__REDIRECT__
__SSL__
__VHOST_DOCROOT__
__VHOST_RPROXY__
__PHP_FPM__
__ALIASES__
__DENIES__
__SERVER_STATUS__
# Custom directives
__CUSTOM__
}
###
### vHost Type (normal or reverse proxy)
###
vhost_type:
# Normal vHost (-p)
docroot: |
# Define the vhost to serve files
root "__DOCUMENT_ROOT__";
index __INDEX__;
# Reverse Proxy (-r)
rproxy: |
# Define the vhost to reverse proxy
location __LOCATION__ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass __PROXY_PROTO__://__PROXY_ADDR__:__PROXY_PORT__;
}
###
### Optional features to be enabled in vHost
###
features:

# SSL Configuration
ssl: |
ssl_certificate __SSL_PATH_CRT__;
ssl_certificate_key __SSL_PATH_KEY__;
ssl_protocols __SSL_PROTOCOLS__;
ssl_prefer_server_ciphers __SSL_HONOR_CIPHER_ORDER__;
ssl_ciphers __SSL_CIPHERS__;
# Redirect to SSL directive
redirect: |
return 301 https://__VHOST_NAME__:__SSL_PORT__$request_uri;
# PHP-FPM will not be applied to a reverse proxy!
php_fpm: |
# PHP-FPM Definition
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# CHANGED:
#location ~ \.php?$ {
location ~ \.php($|/) {
set $script $uri;
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
}
# end of CHANGED:
try_files $uri = 404;
include fastcgi_params;
# https://stackoverflow.com/questions/1733306/nginx-errors-readv-and-recv-failed/51457613#51457613
fastcgi_keep_conn off;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass __PHP_ADDR__:__PHP_PORT__;
fastcgi_read_timeout __PHP_TIMEOUT__;
fastcgi_index index.php;
fastcgi_intercept_errors on;
}
alias: |
# Alias Definition
location ~ __ALIAS__ {
root __PATH__;
__XDOMAIN_REQ__
}
deny: |
# Deny Definition
location ~ __REGEX__ {
deny all;
}
server_status: |
# Status Page
location ~ __REGEX__ {
stub_status on;
access_log off;
}
xdomain_request: |
# Allow cross domain request from these hosts
if ( $http_origin ~* (__REGEX__) ) {
add_header "Access-Control-Allow-Origin" "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Max-Age' 0;
return 200;
}

0 comments on commit 018bea9

Please sign in to comment.