# server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; # server_tokens off; # # root /app/public; # index index.php; # # location / { # try_files $uri $uri.php $uri/ /index.php$is_args$args; # } # # location ~ \.php$ { # include fastcgi_params; # fastcgi_pass php:9000; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # } # } ## existing .htaccess # # mod_rewrite starts here # RewriteEngine on # # # Prevent directory listings # Options All -Indexes # # # # does not apply to existing directories, meaning that if the folder exists on the server then don't change anything and don't run the Rule! # # RewriteCond %{REQEUSTED_FILENAME} !-d # RewriteCond %{REQUEST_FILENAME}\.html -f # RewriteRule ^(.*)$ $1.html [NC,L] # # RewriteCond %{REQUEST_FILENAME}\.php -f # RewriteRule ^(.*)$ $1.php [NC,L] # # ErrorDocument 404 /404 # ErrorDocument 403 /403 # # # order allow,deny # deny from all # # write a nginx config combining the above .htaccess and the existing nginx config server { listen 80 default_server; listen [::]:80 default_server; server_name _; server_tokens off; root /app/public; index index.html index.htm index.php; # make .well-known directory accessible location ~ /.well-known { allow all; # serve all files in the .well-known directory # directly without passing the request to the backend try_files $uri =404; } location / { if (!-e $request_filename){ rewrite ^(.*)$ /$1.php; } try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_page 404 /404; error_page 403 /403; location = /404 { root /app/public; } location = /403 { root /app/public; } location = /template.php { deny all; } }