Skip to content

Instantly share code, notes, and snippets.

What would you like to do? Apache and Nginx configurations
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see:
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
UseCanonicalName Off
# <subdomain> setup
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.web\$
RewriteRule ^(.*)$ /var/www/%1/web/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^([^.]+)\.public\$
RewriteRule ^(.*)$ /var/www/%1/public/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^([^.]+)\.static\$
RewriteRule ^(.*)$ /var/www/%1/static/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^([^.]+)\$
RewriteRule ^(.*)$ /var/www/%1/$1 [NC,L]
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
<Directory /var/www/>
#Options Indexes FollowSymLinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
php_value xdebug.remote_port 9009
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Server configuration
server {
listen 80 default_server;
listen [::]:80 default_server;
# Server name
server_name ~^(?<subdomain>.+)$;
# Web root
root /var/www/$subdomain;
# Index
index index.php index.html;
# Try static files first and the default to index.php
location / {
try_files $uri $uri/ /index.php?$query_string;
# Pass the PHP scripts to FastCGI server
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
location ~ /\.ht {
deny all;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.