【问题标题】:Symfony, nginx and "File not found."Symfony、nginx 和“找不到文件”。
【发布时间】:2022-02-19 00:38:27
【问题描述】:

OVH 服务器上的 nginx 实例有问题。

当我转到我的页面时,出现“找不到文件”错误。

/etc/nginx/sites-available/defaul 来自官方 Symfony 配置: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html#nginx

server {
    server_name 51.255.193.179;
    root /root/www/harccal/web;

    location / {
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

错误日志:

2016/01/13 23:57:04 [crit] 9372#0: *9 stat() "/root/www/harccal/web/" failed (13: Permission denied), client: 89.70.84.185, server: 51.255.193.179, request: "GET / HTTP/1.1", host: "51$
2016/01/13 23:57:04 [crit] 9372#0: *9 realpath() "/root/www/harccal/web" failed (13: Permission denied), client: 89.70.84.185, server: 51.255.193.179, request: "GET / HTTP/1.1", host: $
2016/01/13 23:57:04 [error] 9372#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 89.70.84.185, server: 51.255.193.179, request: "$

前提:

:~/www/harccal# ls -al
total 1332
drwxr-xr-x  8 root root    4096 sty 13 22:02 .
drwxr-xr-x  3 root root    4096 sty 13 21:51 ..
drwxr-xr-x  6 root root    4096 sty 13 22:24 app
drwxr-xr-x  2 root root    4096 sty 13 22:13 bin
-rw-r--r--  1 root root    2669 sty 13 21:51 composer.json
-rw-r--r--  1 root root   67193 sty 13 22:13 composer.lock
-rwxr-xr-x  1 root root 1248055 sty 13 22:02 composer.phar
drwxr-xr-x  8 root root    4096 sty 13 21:51 .git
-rw-r--r--  1 root root      80 sty 13 21:51 .gitignore
-rw-r--r--  1 root root      85 sty 13 21:51 README.md
drwxr-xr-x  4 root root    4096 sty 13 21:51 src
drwxr-xr-x 16 root root    4096 sty 13 22:24 vendor
drwxrwxr-x  7 root root    4096 sty 13 22:03 web

/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

我没有更多的日志。或者我不知道什么时候找到它..

【问题讨论】:

    标签: symfony nginx


    【解决方案1】:

    /root 目录默认没有other 用户的读取权限,这是非常合理的。而且很可能它具有700 权限。

    接下来会发生什么 - 您的网络服务器用户 www-data 尝试读取 /root/www/harccal/web 中的文件。但是链中的第一个目录 (/root) 不能被它读取。所以它以9 stat() "/root/www/harccal/web/" failed (13: Permission denied) 结束

    为了使文件可读 - 每个父目录也必须是可遍历的。

    解决方案:您最好将您的应用程序移动到另一个目录,该目录可供网络服务器用户访问。

    【讨论】:

      【解决方案2】:

      我有同样的问题。经过3个小时的调试,来回更改权限,重新启动一切我注意到我的本地app.php没有上传到远程主机。

      因此,如果您遇到同样的错误,一种可以确保您的所有本地文件都正确上传到您的虚拟主机。

      【讨论】:

        猜你喜欢
        • 2015-04-30
        • 2018-02-05
        • 2017-09-05
        • 2020-08-11
        • 1970-01-01
        • 2016-06-30
        • 2014-08-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多