我正在使用kirby cms,并在开箱即用的盒子里附带了这棵树结构,其中一切都在webroot上:
├── assets
│ ├── css
│ │ └── main.css
│ └── js
│ └── main.js
├── content
├── kirby
├── panel
│ ├── assets
│ │ ├── main.css
│ │ └── main.js
│ └── index.php
├── site
└── index.php
这样,我可以通过https://example.com
和面板通过https://example.com/panel
访问该站点。
我只想在Webroot上留下index.php
,并提出以下结构:
├── content
├── kirby
├── panel
│ ├── assets
│ │ ├── main.css
│ │ └── main.js
│ └── index.php
├── public
│ ├── css
│ │ └── main.css
│ ├── js
│ │ └── main.js
│ └── index.php
└── site
我能够通过将/public
附加到root
指令来使该网站与NGINX合作:
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/example.com/public;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# Media: images, icons, video, audio, HTC
location ~ .(jpe?g|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~ .(css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
# Removes trailing slashes
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Panel links
location /panel {
index index.php;
try_files $uri $uri/ /panel/index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
现在,我和我如何让面板指向新的位置并响应PHP请求并提供资产?
您可以尝试这样的东西。
root /home/example.com;
...
location /public {
index index.php;
try_files $uri $uri/public/ /public/index.php?$query_string;
}
location /panel {
index index.php;
try_files $uri $uri/panel/ /panel/index.php?$query_string;
}