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

zd287kbt  于 5个月前  发布在  Nginx
关注(0)|答案(7)|浏览(69)

我在Ubuntu 10.10上沿着了nginx 0.7.67和php-php。我试图让我的基于前端控制器的PHP框架运行,但除了index.php给予一个403错误。
例如:

  1. http://mysite.com/styles/style.css-禁止访问
  2. http://mysite.com/scripts/script.css-禁止访问
  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;
    }

}

字符串
有什么建议可以解决上面的问题吗?
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"

nbnkbykc

nbnkbykc1#

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

chmod -R +rx css
chmod -R +rx js

字符串
提供读取和执行权限。-R是递归的。只对你想让全世界都能读的文件这样做!

lokaqttq

lokaqttq2#

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

user myuser mygroup;

字符串

nhjlsmyf

nhjlsmyf3#

在您的位置行中尝试以下操作:

location ~* ^.+\.(js|css|png|jpg|jpeg|gif|ico|html)$ {

字符串

location ~* ^.+.(js|css|png|jpg|jpeg|gif|ico|html)$ {

jmo0nnb3

jmo0nnb34#

我也遇到了这个问题
我遇到的原因是我把项目放在/root中
root的权限是
drwx-- 14根根
所以我把项目搬到了/家。

qzlgjiam

qzlgjiam5#

确保每个顶级目录都有权限级别和index.html。大多数情况下,你只需要复制你想在/www中看到的文件并将其重命名为index.html,确保新的index.html具有正确的权限(当然,要确保777只是为了测试)。

7ajki6be

7ajki6be6#

我需要写替代解决方案这个问题.我迁移到plesk服务器的WordPress,我得到这个错误与CSS和JS脚本. Nginx配置产生一个错误获取JS和CSS文件.如果WordPress错误加载CSS和JS脚本(禁止),它可能是由于Nginx和Apache的配置.
打开配置nginx和apache的盒子:
静态文件的智能处理-> DONT THERAKED
这解决了我的问题。我希望其他人也pymessoft.com

cidc1ykv

cidc1ykv7#

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;

} <--- you forgot this one

        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;
        }

    }

字符串
在定义位置之前,您必须关闭server{}
或更改所有者的文件www-data或apache如果你没有访问这些文件.

相关问题