Skip to content

Instantly share code, notes, and snippets.

@iconnor
Created July 11, 2019 05:59
Show Gist options
  • Save iconnor/dec415fdb11d92cb41e4dcc8dd8c848d to your computer and use it in GitHub Desktop.
Save iconnor/dec415fdb11d92cb41e4dcc8dd8c848d to your computer and use it in GitHub Desktop.
PHP nginx conf file for Docker
# vim: ft=nginx ts=2 sw=2
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
# Make site accessible from http://localhost/
server_name localhost;
location / {
root /var/www/html/public;
index index.php index.html index.htm;
server_tokens off;
# First attempt to serve request as file, then as directory, then
# /index.php.
try_files $uri $uri/ @reroute;
# include /etc/nginx/naxsi.rules
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { access_log off; log_not_found off; }
location @reroute {
rewrite ^ /index.php last;
}
# error_page 404 /index.php;
# pass the PHP scripts to php-fpm
# Note: \.php$ is susceptible to file upload attacks
# Consider using: "location ~ ^/(index|app|app_dev|config)\.php(/|$) {"
location ~ \.php$ {
root /var/www/html/public;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param LARA_ENV local; # Environment variable for Laravel
fastcgi_param HTTPS off;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment