Nginx,从单独的目录运行脚本

问题描述 投票:0回答:1

文件结构:

  • /var/www/example.com - Laravel 站点的目录
  • /var/www/cms - WordPress 博客的目录

我想通过地址 http://example.com/blogs 打开我的博客 (http://example.com/blogs/article/)

我的 nginx 配置文件

server {
    server_name example.com;
    charset UTF-8;
    index index.php;
    root /var/www/example.com/public;
    include /etc/nginx/vhosts-includes/*.conf;

    location ^~ /blogs/ {
        alias /var/www/cms;
                index index.php;
        try_files $uri $uri/ /index.php;

        location ~ [^/]\.ph(p\d*|tml)$ {
                     try_files /does_not_exists @php;
                }
    }

    location / {
        if ($http_host !~ "^example.com") {
            return 301 $scheme://example.com$request_uri;
        }

        try_files $uri $uri/ /index.php?_url=$uri&$args;

        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }

    location @php {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
    }

    location @fallback {
    }
    ssi on;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    listen 443 ssl http2;
}

drwxr-xr-x 2 www-data www-data 4096 10 月 7 日 12:36 /var/www/cms

-rwxr-xr-x 1 www-data www-data 10 月 7 日 28 日 12:36 /var/www/cms/index.php

但是我收到错误:

[错误] 1193696#1193696: *禁止“/var/www/cms”的69目录索引,客户端:89.69.169.171,服务器:example.com,请求:“GET /blogs/ HTTP/2.0”,主机: “example.com”

我尝试添加

autoindex on;

    location ^~ /blogs/ {
        alias /var/www/cms;
                index index.php;
        try_files $uri $uri/ /index.php;
        autoindex on;

        location ~ [^/]\.ph(p\d*|tml)$ {
                    try_files /does_not_exists @php;
                }
    }

但出现下一个错误 [警告] 1192265#1192265: *92 在读取上游时,上游响应被缓冲到临时文件 /var/lib/nginx/fastcgi/1/00/0000000001,客户端:89.69.169.171,服务器:example.com,请求: “GET /_debugbar/assets/javascript/?v=1695127990 HTTP/2.0”,上游:“fastcgi://unix:/var/run/php/php8.2-fpm.sock:”,主机:“example.com ”,引荐来源:“https://example.com/blogs/”

如何修复此类错误?

php nginx nginx-config
1个回答
0
投票
    location /blogs {
        alias "/var/www/cms";
        try_files $uri $uri/ @blogs;
        location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /var/www/blogs/index.php;
        }
    }
    location @blogs {
        rewrite /blogs/(.*)$ /blogs/index.php?/$1 last;
    }
© www.soinside.com 2019 - 2024. All rights reserved.