[英]Nginx - Cant fin index.php if not under / (root) location
I have trouble to run davical (php) web calendar. 我无法运行davical(php)网络日历。 There is no errol log in nginx error logs.
nginx错误日志中没有错误日志。 When is calendar under \\ location everything work.
日历何时在\\位置下,一切正常。 But when i have calendar under /calendar location.
但是当我在/ calendar位置下有日历时。 it returns 404.
它返回404。
default server root is: /usr/share/nginx/html/default 默认服务器根目录为:/ usr / share / nginx / html / default
calendar index.php path: /usr/share/nginx/html/calendar/davical/htdocs\\index.php 日历index.php路径:/usr/share/nginx/html/calendar/davical/htdocs\\index.php
os: Centos 7 操作系统:Centos 7
server {
listen 80 default_server;
server_name my_domain_name;
return 301 https://$server_name$request_uri;
}
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 {
}
}
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;
}
Your existing location ~ \\.php$
block serves the /usr/share/nginx/html/default
root. 您现有的
location ~ \\.php$
块用作/usr/share/nginx/html/default
根目录。 You need a nested location
to process PHP files under the /calendar
URI. 您需要一个嵌套
location
来处理/calendar
URI下的PHP文件。
Assuming that your calendar app is designed to work within a subfolder, this may work for you: 假设您的日历应用旨在在子文件夹中运行,那么这可能对您有效:
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;
}
}
Use the ^~
modifier to prevent the other location ~ \\.php$
block from taking precedence (see this document for more). 使用
^~
修饰符可防止其他location ~ \\.php$
块优先(请参阅本文档以获取更多信息)。 Use $request_filename
, as it works with alias
. 使用
$request_filename
,因为它与alias
。 Avoid using try_files
with alias
(see this issue ). 避免将
try_files
与alias
一起使用(请参阅此问题 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.