首页 > 解决方案 > Nginx 在子目录中访问 PHP(已解决)

问题描述

已解决:我缺少 simplexml,我只需要安装它(Ubuntu)sudo apt-get install php-xml

我正在尝试访问该 presskit 系统使用的具有 index.php 和 sheet.php 的子目录 /presskit。不幸的是,我不太清楚如何访问它,我得到 404,被重定向到我的主页,或者它只是说无法处理请求。

我试图访问的文件位于 /var/www/html/spreadcamp.com/public_html/presskit/index.php

我试图通过访问https://spreadcamp.com/presskit/index.php来访问

有人知道我在做什么错吗?

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name spreadcamp.com www.spreadcamp.com;
    return 301 https://$server_name$request_uri;
}

server {

    # SSL configuration
    #
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;
    ssl_client_certificate /etc/ssl/cloudflare.crt;
    ssl_verify_client on;

    root /var/www/html/spreadcamp.com/public_html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.php;

    server_name spreadcamp.com www.spreadcamp.com;

    proxy_cache one;
    

    gzip off;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ^~ /presskit {
        index index.php;
        alias /var/www/html/spreadcamp.com/public_html/presskit;

        if (!-e $request_filename) { rewrite ^ /presskit/index.php last; }

        location ~ \.php$ {
            if (!-f $request_filename) { return 404; }

            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            }
    }


    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    
        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        # With php-cgi (or other tcp sockets):
        #fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

标签: phpnginxnginx-confignginx-location

解决方案


推荐阅读