簡體   English   中英

Nginx為所有PHP文件提供404服務,但index.php

[英]nginx serves 404 for all php files but index.php

我是nginx的新手,正在嘗試在其上移動wordpress網站。

問題是我需要運行一個名為“ installer.php”的文件,nginx會為此顯示一個404錯誤(來自domain / rocketstack / installer.php)。 如果我添加了特定的“位置”指令,則會返回“未指定輸入文件”錯誤(不確定我是否正確執行此操作)。 訪問domain / rocketstack / index.php直接返回相同的404,但如果我轉到domain / rocketstack /,則可以工作(我猜這很好)。

我在ubuntu 18.04上使用php7.2-fpm,“ installer.php”在/ var / www / rocketstack /中,具有權限644。cgi.fix_pathinfo cgi.fix_pathinfo=0在php.ini中設置。 要設置環境,我使用了本指南: https : //www.wpintense.com/2018/10/20/installing-the-fastest-wordpress-stack-ubuntu-18-mysql-8/

這是我的/etc/sites-available/rocketstack.conf文件

我怎樣才能解決這個問題? 我為此花了很多時間! 然而,它必須是如此簡單! 非常感謝

# This config file uses nginx fastcgi-cache
fastcgi_cache_path /var/www/cache levels=1:2 keys_zone=rocketstack:100m inactive=60m;

server {
    listen 80;
    listen [::]:80;
    server_name _;

    root /var/www/rocketstack;

    index index.php index.htm index.html;

    access_log /var/log/nginx/rocketstack_access.log;
    error_log /var/log/nginx/rocketstack_error.log;

    include snippets/acme-challenge.conf;

    # Exclusions
    include snippets/exclusions.conf;

    # Security
    include snippets/security.conf;

    # Static Content
    include snippets/static-files.conf;

    # Fastcgi cache rules
    include snippets/fastcgi-cache.conf;

    include snippets/limits.conf;

    include snippets/nginx-cloudflare.conf;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ (^|/)\. {
        return 403;
    }
    location ~/installer.php {
    root /var/www/rocketstack/;
        fastcgi_index  installer.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include snippets/fastcgi-params.conf;
    include fastcgi.conf;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include snippets/fastcgi-params.conf;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

        # Skip cache based on rules in snippets/fastcgi-cache.conf.
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;

        # Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
        fastcgi_cache rocketstack;

        # Define caching time.
        fastcgi_cache_valid 60m;
        #increase timeouts
        fastcgi_read_timeout 6000;
        fastcgi_connect_timeout 6000;
        fastcgi_send_timeout 6000;
        proxy_read_timeout 6000;
        proxy_connect_timeout 6000;
        proxy_send_timeout 6000;
        send_timeout 6000;

        #these lines should be the ones to allow Cloudflare Flexible SSL to be used so the server does not need to decrypt SSL
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-NginX-Proxy true;

    }

}

server {
    listen              443 ssl http2 default_server;
    listen              [::]:443 ssl http2 default_server ;
    server_name _;

    root /var/www/rocketstack;

    index index.php index.htm index.html;

    access_log /var/log/nginx/rocketstack_ssl_access.log;
    error_log /var/log/nginx/rocketstack_ssl_error.log;

    #once you have SSL certificates using LetsEncrypt you can alter the paths in the two lines below to reflect your domain and uncomment the lines by removing the leading # symbol
    #ssl_certificate           /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    #ssl_certificate_key       /etc/letsencrypt/live/yourdomain.com/privkey.pem;

    # Exclusions
    include snippets/exclusions.conf;

    # Security
    include snippets/security.conf;

    # Static Content
    include snippets/static-files.conf;

    # Fastcgi cache rules
    include snippets/fastcgi-cache.conf;

    include snippets/limits.conf;

    include snippets/nginx-cloudflare.conf;

    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include snippets/fastcgi-params.conf;

        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

        # Skip cache based on rules in snippets/fastcgi-cache.conf.
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;

        # Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
        fastcgi_cache rocketstack;

        # Define caching time.
        fastcgi_cache_valid 60m;
        #increase timeouts
        fastcgi_read_timeout 6000;
        fastcgi_connect_timeout 6000;
        fastcgi_send_timeout 6000;
        proxy_read_timeout 6000;
        proxy_connect_timeout 6000;
        proxy_send_timeout 6000;
        send_timeout 6000;

        #these lines should be the ones to allow Cloudflare Flexible SSL to be used so the server does not need to decrypt SSL if you wish
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-NginX-Proxy true;

    }

}

通過反復試驗修復。 當前設置:

    location ~ \installer.php {
    try_files $uri $uri/ /installer.php?$args;
    fastcgi_index installer.php;
    include snippets/fastcgi-params.conf;
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

問題是我沒有告訴nginx在哪里選擇installer.php,而是通過try_files實現的。 位置的根設置也是多余的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM