Rya*_*yan 158 configuration nginx domain-name http-status-code-403
我有3个域名,我正在尝试使用Nginx在一台服务器(数字海洋液滴)上托管所有3个站点.
mysite1.name mysite2.name mysite3.name
其中只有一个有效.另外两个导致403错误(以相同的方式).
在我的nginx错误日志中,我看到:[error] 13108#0: *1 directory index of "/usr/share/nginx/mysite2.name/live/" is forbidden.
我的网站启用配置是:
server {
server_name www.mysite2.name;
return 301 $scheme://mysite2.name$request_uri;
}
server {
server_name mysite2.name;
root /usr/share/nginx/mysite2.name/live/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
所有3个站点都有几乎相同的配置文件.
每个站点的文件都在/usr/share/nginx/mysite1.name/someFolder等文件夹中,然后/usr/share/nginx/mysite1.name/live是一个符号链接.(与mysite2和mysite3相同.)
我看过禁止所有文件的Nginx 403,但这没有用.
关于可能出错的任何想法?
JCM*_*JCM 135
如果您关闭了目录索引,并且遇到此问题,可能是因为您使用的try_files有一个目录选项:
location / {
try_files $uri $uri/ /index.html index.php;
} ^ that is the issue
Run Code Online (Sandbox Code Playgroud)
删除它,它应该工作:
location / {
try_files $uri /index.html index.php;
}
Run Code Online (Sandbox Code Playgroud)
从我所看到的,这是因为nginx将尝试索引目录,并被自己阻止.抛出OP提到的错误.
Rya*_*yan 62
server {
server_name www.mysite2.name;
return 301 $scheme://mysite2.name$request_uri;
}
server {
#This config is based on https://github.com/daylerees/laravel-website-configs/blob/6db24701073dbe34d2d58fea3a3c6b3c0cd5685b/nginx.conf
server_name mysite2.name;
# The location of our project's public directory.
root /usr/share/nginx/mysite2/live/public/;
# Point index to the Laravel front controller.
index index.php;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Run Code Online (Sandbox Code Playgroud)
然后浏览器中唯一的输出是Laravel错误:"糟糕,看起来出了问题."
不要跑chmod -R 777 app/storage(注意).使世界可写的东西是安全性差的.
chmod -R 755 app/storage 工作,更安全.
maz*_*maz 55
如果您只是尝试列出目录内容,请使用autoindex on;如下:
location /somedir {
autoindex on;
}
Run Code Online (Sandbox Code Playgroud)
Man*_*ddy 19
我
在/var/log/nginx/error.log的错误日志中遇到了类似的错误
---"403 Forbidden"网页
---"13:Permission denied"
以下3个步骤对我有用:
user1@comp1:/home/www/
Run Code Online (Sandbox Code Playgroud)
所以,我的用户名是"user1"(从上面)
# user www-data;
user user1;
Run Code Online (Sandbox Code Playgroud)
sudo nginx -s reload
Run Code Online (Sandbox Code Playgroud)
另外,我已经应用了文件/文件夹权限(在我执行上述3个步骤之前)
(755到我的目录,比如说/ dir1 /)&(644用于该目录下的文件):(
我不确定,如果这个额外的步骤是真的需要,只需3步以上即可)
chmod 755 ./dir1/
chmod 644 ./dir1/*.*
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助快速的人.祝你好运.
RAZ*_*229 10
以下是我在 Kali 机器上修复该问题的方法:
定位到目录:
cd /etc/nginx/sites-enabled/
编辑“默认”配置文件:
sudo nano default
在块中添加以下行location:
location /yourdirectory {
autoindex on;
autoindex_exact_size off;
}
Run Code Online (Sandbox Code Playgroud)
请注意,我仅在特定目录中激活了自动索引
/yourdirectory。否则,它将为您计算机上的所有文件夹启用,而您并不需要它。
现在重新启动您的服务器,它现在应该可以工作了:
sudo service nginx restart
事实上,您需要检查几件事.1.检查你的nginx的运行状态
ps -ef|grep nginx
ps aux|grep nginx|grep -v grep
Run Code Online (Sandbox Code Playgroud)
在这里,我们需要检查谁正在运行nginx.请记住用户和组
检查文件夹的访问状态
ls -alt
与nginx的文件夹状态进行比较
(1)如果文件夹的访问状态不正确
sudo chmod 755 /your_folder_path
Run Code Online (Sandbox Code Playgroud)
(2)如果文件夹的用户和组与nginx的运行不同
sudo chown your_user_name:your_group_name /your_folder_path
Run Code Online (Sandbox Code Playgroud)
并更改nginx的运行用户名和组
nginx -h
Run Code Online (Sandbox Code Playgroud)
找到nginx配置文件的位置
sudo vi /your_nginx_configuration_file
//in the file change its user and group
user your_user_name your_group_name;
//restart your nginx
sudo nginx -s reload
Run Code Online (Sandbox Code Playgroud)
因为nginx默认运行的用户是nobody而group是nobody.如果我们没有注意到这个用户和组,将引入403.
小智 7
看起来像是一些权限问题。
尝试将您在 mysite1 中所做的所有权限设置为其他站点。
默认文件权限应该是 644 和 dirs 755。还要检查运行 nginx 的用户是否有权读取这些文件和目录。
我有同样的问题,日志文件显示我这个错误:
2016/03/30 14:35:51 [error] 11915#0: *3 directory index of "path_scripts/viewerjs/" is forbidden, client: IP.IP.IP.IP, server: domain.com, request: "GET /scripts/viewerjs/ HTTP/1.1", host: "domain", referrer: "domain.com/new_project/do_update"
Run Code Online (Sandbox Code Playgroud)
我正在托管一个带有codeignitor框架的PHP应用程序.当我想查看我收到的上传文件时403 Error.
问题是,nginx.conf 没有正确定义.代替
index index.html index.htm index.php
Run Code Online (Sandbox Code Playgroud)
我只包括在内
index index.php
Run Code Online (Sandbox Code Playgroud)
我的root中有一个index.php,我认为这就够了,我错了;)提示给了我NginxLibrary
你可能因为Nginx策略(例如"deny")而得到这个,或者你可能因为Nginx配置错误而得到这个,或者你可能因文件系统限制而得到这个.
您可以确定它是否是后者(并且可能通过使用strace看到错误配置的证据(除了OP将无法访问它):
# pidof nginx
11853 11852
# strace -p 11853 -p 11852 -e trace=file -f
Process 11853 attached - interrupt to quit
Process 11852 attached - interrupt to quit
[pid 11853] stat("/var/www/html/kibanaindex.html", 0x7ffe04e93000) = -1 ENOENT (No such file or directory)
[pid 11853] stat("/var/www/html/kibana", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
^CProcess 11853 detached
Process 11852 detached
Run Code Online (Sandbox Code Playgroud)
在这里我正在检查nginx在运行测试时完成的文件系统活动(我和你有同样的错误).
这是我当时配置的一部分
location /kibana/3/ {
alias /var/www/html/kibana;
index index.html;
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,正如strace非常清楚地表明的那样,"别名"与"索引"的加入并不是我所期望的,似乎我需要养成总是用/附加目录名的习惯,所以在我的情况下,以下工作:
location /kibana/3/ {
alias /var/www/html/kibana/;
index index.html;
}
Run Code Online (Sandbox Code Playgroud)
对我来说,问题是除基本路线之外的任何路线都在工作,添加这一行解决了我的问题:
index index.php;
Run Code Online (Sandbox Code Playgroud)
完整的东西:
server {
server_name example.dev;
root /var/www/example/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Run Code Online (Sandbox Code Playgroud)
更改try_files指向index.php路径,在您提到的“Laravel”中,它应该是这样的
location / {
try_files $uri $uri/ /public/index.php$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
在“codeigniter”项目中尝试这样
location / {
try_files $uri $uri/ /public_web/index.php$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
392674 次 |
| 最近记录: |