簡體   English   中英

Nginx-如果不在/(根目錄)位置,則無法刪除fin index.php

[英]Nginx - Cant fin index.php if not under / (root) location

我無法運行davical(php)網絡日歷。 nginx錯誤日志中沒有錯誤日志。 日歷何時在\\位置下,一切正常。 但是當我在/ calendar位置下有日歷時。 它返回404。

默認服務器根目錄為:/ usr / share / nginx / html / default

日歷index.php路徑:/usr/share/nginx/html/calendar/davical/htdocs\\index.php

操作系統:Centos 7

server {
    listen 80 default_server;
    server_name my_domain_name;
    return 301 https://$server_name$request_uri;
}

Https

server {
    listen 443 ssl http2;
    server_name my_domain_name;

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;

    ssl on;
    ssl_certificate "/etc/pki/tls/certs/nginx/certificate.pem";
    ssl_certificate_key "/etc/pki/tls/certs/nginx/privatekey.pem";
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_session_tickets off;
    ssl_dhparam "/etc/pki/tls/certs/nginx/dhparam.pem";
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    resolver 8.8.8.8 8.8.4.4;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate "/etc/pki/tls/certs/nginx/certificate.pem";
    add_header Strict-Transport-Security "max-age=31536000;includeSubdomains; preload";

    root /usr/share/nginx/html/default;
    index index.php index.html index.htm;
    include /etc/nginx/default.d/php-fpm.conf;

    location /calendar {
            alias /usr/share/nginx/html/calendar/davical/htdocs;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

php-fpm.conf

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_param HTTPS on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME
    $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

您現有的location ~ \\.php$塊用作/usr/share/nginx/html/default根目錄。 您需要一個嵌套location來處理/calendar URI下的PHP文件。

假設您的日歷應用旨在在子文件夾中運行,那么這可能對您有效:

location ^~ /calendar {
    alias /usr/share/nginx/html/calendar/davical/htdocs;
    index index.php;

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

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

        include        fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $request_filename;
    }
}

使用^~修飾符可防止其他location ~ \\.php$塊優先(請參閱本文檔以獲取更多信息)。 使用$request_filename ,因為它與alias 避免將try_filesalias一起使用(請參閱此問題 )。

暫無
暫無

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

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