Last active
June 27, 2018 14:22
-
-
Save ykocaman/e15df01bb6652f8fb40a2e0502db1795 to your computer and use it in GitHub Desktop.
Nginx development config with all php version. For example http://test.dev7.lo runs index.php in /home/www/test with version 7.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/etc/nginx/sites-enabled/development | |
server { | |
listen 80; | |
listen 443 ssl; | |
#parse domain | |
server_name | |
~^(?<domain_name>.+)\.(?<dir_name>[^\d]*)(?<version>\d+)\.lo$ | |
~^(?<domain_name>.+)\.(?<dir_name>.+)\.lo$; | |
#root path definition | |
set $root_path /home/www/$domain_name/$dir_name/; | |
if ($dir_name = dev) | |
{ | |
set $root_path /home/www/$domain_name/; | |
} | |
root $root_path; | |
#php default version | |
set $php_version 7.2; | |
#php versions | |
if ($version = 5) | |
{ | |
set $php_version 5.6; | |
} | |
if ($version = 7) | |
{ | |
set $php_version 7.0; | |
} | |
if ($version = 71) | |
{ | |
set $php_version 7.1; | |
} | |
set $default_file "index"; | |
if ($dir_name ~ web) | |
{ | |
set $default_file "app_dev"; | |
} | |
index index.html index.php app.php; | |
location / { | |
try_files $uri $uri/ /$default_file.php?$query_string; | |
} | |
# catch all | |
#error_page 404 /index.php; | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_read_timeout 6000; | |
fastcgi_pass unix:/var/run/php/php$php_version-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param HTTPS off; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
ssl_certificate /etc/nginx/ssl/nginx.crt; | |
ssl_certificate_key /etc/nginx/ssl/nginx.key; | |
# We don't need .ht files with nginx. | |
location ~ /\.ht { | |
deny all; | |
} | |
# Set header expirations on per-project basis | |
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ { | |
log_not_found off; | |
access_log off; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/etc/dnsmasq.conf | |
# Add other name servers here, with domain specs if they are for | |
# non-public domains. | |
#server=/localnet/192.168.0.1 | |
server=8.8.8.8 | |
server=8.8.4.4 | |
# Add domains which you want to force to an IP address here. | |
# The example below send any host in double-click.net to a local | |
# web-server. | |
#address=/double-click.net/127.0.0.1 | |
address=/lo/127.0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment