0

我正在使用 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.

我只想将网站index.php留在 webroot 上,并提出以下结构:

├── content
├── kirby
├── panel
│   ├── assets
│   │   ├── main.css
│   │   └── main.js
│   └── index.php
├── public
│   ├── css
│   │   └── main.css
│   ├── js
│   │   └── main.js
│   └── index.php
└── site

通过附加指令,我能够使该站点与 Nginx/public一起使用:root

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 请求并提供资产?

4

1 回答 1

0

你可以尝试这样的事情。

    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;
    }
于 2020-10-08T09:21:38.290 回答