Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Created October 5, 2017 08:57
Show Gist options
  • Save lixingcong/e0368d111cf4e876e558c23739e12d04 to your computer and use it in GitHub Desktop.
Save lixingcong/e0368d111cf4e876e558c23739e12d04 to your computer and use it in GitHub Desktop.
php source files in subfolder, using nginx
✔ [/home/ubuntu/nginx_html/]
$ tree
.
├── homepage.php
├── home.php
├── index.html
└── xxoo
├── back.php
└── backup.php
1 directory, 5 files
✔ [/home/ubuntu/nginx_html/]
$ wget -O - http://h2.lan/index.html
$ wget -O - http://h2.lan/home.php
$ wget -O - http://h2.lan/xxoo/back.php
$ wget -O - http://h2.lan/bak/back.php
server {
listen 80;
server_name h2.lan;
root /home/ubuntu/nginx_html/;
location / {
index index.html;
}
location ~ (home|homepage)\.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# /bak was mapped to home/ubuntu/nginx_html/xxoo/
location /bak{
alias /home/ubuntu/nginx_html/xxoo/;
location ~ ^/bak/(back|backup)\.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$1.php;
include /etc/nginx/fastcgi_params;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment