Nginx 对 CSS/JS 文件给出 403 错误
我在 Ubuntu10.10 上设置了 nginx 0.7.67 以及 php-cli 。我试图让基于前端控制器的 PHP 框架运行,但除 index.php 之外的所有页面都会出现 403 错误。
例如:
- http://mysite.com/styles/style.css - 403 禁止
- http://mysite.com/scripts/script.css - 403 禁止
- 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"
I have setup nginx 0.7.67 on Ubuntu10.10 along with php-cli . I'm trying to get my front-controller based PHP framework to run, but all pages except index.php give a 403 error.
Ex :
- http://mysite.com/styles/style.css - 403 Forbidden
- http://mysite.com/scripts/script.css - 403 Forbidden
- http://mysite.com/index.php - Works
My /etc/nginx/sites-enabled/default is as follows
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;
}
}
Any suggestions on how to fix the above?
PS: This is the entry from the error log
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
有同样的问题。只需在我的 CSS 和 JS 文件和文件夹上设置正确的权限即可修复此问题。设置权限要小心!但要使文件在网络上可读,运行服务器进程的用户必须能够读取该文件。
授予读取和执行权限。
-R
用于递归。仅对您希望全世界都可读的文件执行此操作!Had the same problem. Fixed it by simply setting the right permissions on my CSS and JS files and folders. Be careful about setting permissions! But for a file to be readable on the web, it has to be readable by the user running the server process.
Gives read and execute permissions. The
-R
is for recursive. Only do this for files you want readable by the world!替代解决方案:通过编辑 nginx.conf(例如 /usr/local/nginx/conf/nginx.conf)将运行用户更改为这些文件的所有者:
Alt solution: change the run user by editing the nginx.conf (e.g., /usr/local/nginx/conf/nginx.conf) to the owner of those files:
在您的位置行中尝试此操作:
或
Try this in your location line:
or
我也遇到了这个问题
遇到的原因是我把项目放在了 /root 下
root 的权限是
drwx-------- 14 root root
所以我就把项目移到了 /home 下。
I also encountered this problem
The reason I encountered was that I placed the project in /root
The permissions of root are
drwx------ 14 root root
So I just moved the project to /home.
确保每个顶级目录都有权限级别和index.html。大多数时候,您只需复制您想要在 /www 中看到的文件并将其重命名为 index.html,确保新的 index.html 具有正确的权限(当然,777 仅用于测试)。
Make sure that every top level directory has permission levels AND the index.html. Most of the times you will just copy the file you want to see in /www and rename it index.html make sure the new index.html has the right permissions (to be sure 777 just for testing ofcourse).
我需要写这个问题的替代解决方案。
我将 wordpress 迁移到 plesk 服务器,并在 css 和 js 脚本中收到此错误。
Nginx 配置在获取 js 和 css 文件时产生错误。
如果 WordPress 加载 CSS 和 JS 脚本时出错(禁止),
可能是nginx和apache的配置问题。
解锁配置nginx和apache的盒子:
静态文件智能处理->不要检查
这解决了我的问题。我希望其他人也一样
pymessoft.com
i need to write alterative solution to this problem.
I migrate wordpress into plesk server and I get this error with css and js scripts.
Nginx configuration produce a bug getting js and css files.
If a wordpress error loading CSS and JS scripts (forbidden),
it may be due to the configuration of nginx and apache.
UNLOCK the box of configuration nginx and apache:
Intelligent processing of static files -> DONT CHECKED
This solves my problem. I hope others too
pymessoft.com
在定义位置之前,您必须关闭服务器{}。
或者,如果您无权访问这些文件,请将文件的所有者更改为 www-data 或 apache。
you have to close server{} before defining the location.
or change the owner of the files to www-data or apache if you don't have access to the files.