Nginx在所有php错误上显示403页面

我有运行nginx + php-fpm-5.6的Amazon ec2服务器</ p>

它在没有错误时正确打开php页面,但如果发生任何类型的错误(php错误或异常),它总是显示相同的页面( /test.php </ code>是请求的URL):</ p>


禁止</ strong> </ p>

您无权访问此服务器上的/test.php。< / p>

此外,尝试使用ErrorDocument处理请求时遇到403 Forbidden错误。</ p>
</ blockquote>

我试过 更改php“display_errors”选项。</ p>

当我启用它时,所有脚本开始显示403页面。 在php错误日志中,我看到一条警告消息,我应该定义默认时区。 当我用脚本403中的
date_default_timezone_set(...); </ code>定义它时,错误就会出现并且仅在脚本出现错误或者我写时抛出新的异常(); < / code>例如。</ p>

如何将带有错误详细信息的正常错误消息带回文件中?</ p>

UPD。 我的nginx配置:</ p>

  server {
listen 80 default_server;
server_name localhost;

root / var / www / html;
index index.php index .html;

client_max_body_size 200m;
access_log /var/log/nginx/admin.xuno.com.au.access.log;
error_log /var/log/nginx/admin.xuno.com.au。 error.log;

位置〜.php $ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
包括fastcgi_params;
proxy_read_timeout 120; \ n}
}
</ code> </ pre>

主要nginx.conf </ p>

 用户dev-user; 
worker_processes auto; \ n
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include / etc / nginx /mime.types;
default_type application / octet-stream;

log_format main'$ remote_addr - $ remote_user [$ time_local]“$ request”'
'$ stat us $ body_bytes_sent“$ http_referer”'
'“$ http_user_agent”“$ http_x_forwarded_for”';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on ;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}


</ div>

展开原文

原文

I have Amazon ec2 server running nginx + php-fpm-5.6

It opens php pages correctly when there are no errors, but if any kind of error occurs (php error or exception) it always displays the same page (/test.php is the requested url):

Forbidden

You don't have permission to access /test.php on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

I tried changing php "display_errors" option.

When I enable it all scripts begin to show 403 page. In php error log I see a warning message that I should define default timezone. When I define it with date_default_timezone_set(...); in my scripts 403 error goes and appears only when a script has some mistake or if I write throw new Exception(); for example.

How can I bring back normal error messages with details of an error and place in file where it has occured?

Upd. My nginx configuration:

server {
    listen       80 default_server;
    server_name  localhost;

    root /var/www/html;
    index index.php index.html;

    client_max_body_size 200m;
    access_log /var/log/nginx/admin.xuno.com.au.access.log;
    error_log /var/log/nginx/admin.xuno.com.au.error.log;

    location ~ .php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        proxy_read_timeout 120;
    }
}

Main nginx.conf

user dev-user;
worker_processes  auto;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

doubianyu7844
doubianyu7844 在我的本地机器上我有相同的配置,一切都运行良好。我已经修改了你的通知但没有改变。该文件夹及其所有内容属于dev-user:dev-user。
接近 5 年之前 回复
dorpbn1027
dorpbn1027 我无法复制403.你确定用户dev-user可以读取/var/www/html吗?我注意到两个小问题(但不相关),位置正则表达式应该是\.php$(缺少反斜杠),你需要try_files$uri=404;在同一位置内,以确保脚本文件存在。
接近 5 年之前 回复
douzhu5900
douzhu5900 我添加了它。
接近 5 年之前 回复
duanmeng7865
duanmeng7865 你能更新你的问题并添加一个nginx配置文件吗?
接近 5 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐