Nginx为CSS/JS文件提供403错误

Adi*_*dil 10 regex nginx http-status-code-403

我在Ubuntu10.10上设置了nginx 0.7.67以及php-cli.我正在尝试运行基于前端控制器的PHP框架,但除index.php之外的所有页面都会出现403错误.

例如:

  1. http://mysite.com/styles/style.css - 403禁止
  2. http://mysite.com/scripts/script.css - 403禁止
  3. http://mysite.com/index.php - 作品

我的/ etc/nginx/sites-enabled/default如下

server {
    listen          80;
    server_name     mysite.com;

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

    index           index.php index.html;
    root        /full/path/to/public_html;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|html)$ {
            expires max;
    }


    location ~ index.php {
            include     /etc/nginx/fastcgi_params;
            keepalive_timeout 0;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_pass    127.0.0.1:9000;
    }

}
Run Code Online (Sandbox Code Playgroud)

有关如何解决上述问题的任何建议?

PS:这是错误日志中的条目

2010/10/14 19:56:15 [error] 3284#0: *1 open() "/full/path/to/public_html/styles/style.css" 
failed (13: Permission denied), client: 127.0.0.2, server: quickstart.local, 
request: "GET /styles/style.css HTTP/1.1", host: "mysite"
Run Code Online (Sandbox Code Playgroud)

Mic*_*ler 19

有同样的问题.通过简单地在我的CSS和JS文件和文件夹上设置正确的权限来修复它.设置权限时要小心!但是对于可在Web上读取的文件,运行服务器进程的用户必须能够读取该文件.

chmod -R +rx css
chmod -R +rx js
Run Code Online (Sandbox Code Playgroud)

提供读取和执行权限.这-R是递归的.只对想要世界可读的文件执行此操作!


Avi*_*ran 6

替代解决方案:通过编辑 nginx.conf(例如,/usr/local/nginx/conf/nginx.conf)将运行用户更改为这些文件的所有者:

user myuser mygroup;
Run Code Online (Sandbox Code Playgroud)