【发布时间】:2020-10-12 18:03:49
【问题描述】:
我从 SO 和其他在线网站尝试了许多答案,但似乎无法正常工作。
使用 nginx 配置部署我的 laravel 项目时出现 403 禁止错误:
server {
listen 80;
server_name xxxxx.co www.xxxxx.co;
return 301 https://xxxxx.co$request_uri;
}
server {
listen 80;
listen [::]:80;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.xxxxx.co/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.xxxxx.co/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /var/www/www.xxxxx.co/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name xxxxx.co www.xxxxx.co;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;
}
}
/var/www/www.xxxxx.co/public 有这个内容,如果有的话:
admin favicon.ico home index.php web.config
在本地机器上,它工作正常,我看到主页,但使用 nginx 我无法让它工作
编辑 1: 以下是 /var/www/www.xxxxx.co
的权限drwxr-xr-x 13 root root 4096 Oct 10 07:48 .
这是来自 /var/log/nginx/domains/main.xxxxx.co.error.log 的日志
2020/10/10 08:19:39 [error] 19736#19736: *9 directory index of "/var/www/www.xxxxx.co/public/home/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET /home/ HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:20:31 [error] 19736#19736: *9 open() "/var/www/www.xxxxx.co/public/login" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /login HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:20:35 [error] 19736#19736: *9 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:22:03 [error] 19776#19776: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:22:04 [error] 19776#19776: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:24:03 [error] 19825#19825: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:25:31 [error] 19857#19857: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:25:36 [error] 19857#19857: *3 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:26:24 [error] 19873#19873: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:29:14 [error] 19908#19908: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:31:44 [error] 19937#19937: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:31:48 [error] 19937#19937: *1 directory index of "/var/www/www.xxxxx.co/public/home/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET /home/ HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:34:21 [error] 19968#19968: *1 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:36:24 [error] 19968#19968: *3 directory index of "/var/www/www.xxxxx.co/public/" is forbidden, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:38:46 [error] 20024#20024: *2 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:38:50 [error] 20024#20024: *2 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /home/ HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:39:43 [error] 20024#20024: *2 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:40:23 [error] 20024#20024: *2 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /index HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:40:26 [error] 20024#20024: *2 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /home/ HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:53:32 [error] 20220#20220: *36 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "xxxxx.co" 2020/10/10 08:53:46 [error] 20220#20220: *36 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /index HTTP/1.1", host: "xxxxx.co"
2020/10/10 08:53:50 [error] 20220#20220: *41 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /index HTTP/1.1", host: "www.xxxxx.co" 2020/10/10 08:54:19 [error] 20220#20220: *42 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET /index HTTP/1.1", host: "www.xxxxx.co"
2020/10/10 08:54:22 [error] 20244#20244: *1 open() "/var/www/www.xxxxx.co/publicindex.php" failed (2: No such file or directory), client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", host: "www.xxxxx.co" 2020/10/10 09:03:03 [crit] 20322#20322: *2 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstrea>2020/10/10 09:05:47 [crit] 20394#20394: *2 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstrea>2020/10/10 09:05:48 [crit] 20394#20394: *2 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstrea>2020/10/10 13:30:47 [crit] 20394#20394: *224 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.201, server: www.xxxxx.co, request: "GET /ads.txt HTTP/1.1">2020/10/10 13:54:08 [crit] 20394#20394: *257 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 195.154.61.206, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/10 13:57:53 [crit] 20394#20394: *265 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 195.154.61.206, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/10 15:15:46 [crit] 20394#20394: *350 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.203, server: www.xxxxx.co, request: "GET /ads.txt HTTP/1.1">2020/10/10 15:38:08 [crit] 20394#20394: *385 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 62.210.10.77, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstre>2020/10/10 15:38:28 [crit] 20394#20394: *387 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 195.154.63.222, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/10 17:52:32 [crit] 20394#20394: *629 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.94, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstre>2020/10/10 20:00:52 [crit] 20394#20394: *848 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.201, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstr>2020/10/10 21:00:50 [crit] 20394#20394: *900 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.95, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstre>2020/10/10 22:00:32 [crit] 20394#20394: *988 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.205, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstr>2020/10/10 23:22:15 [crit] 20394#20394: *1098 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 182.66.43.161, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/11 00:01:52 [crit] 20394#20394: *1165 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.203, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/11 04:40:28 [crit] 20394#20394: *1609 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 77.30.211.212, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/11 05:32:53 [crit] 20394#20394: *1685 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.205, server: www.xxxxx.co, request: "GET / HTTP/1.1", upst>2020/10/11 08:56:03 [crit] 20394#20394: *1948 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.205, server: www.xxxxx.co, request: "GET /en/desert-one HT>2020/10/11 09:30:17 [crit] 20394#20394: *1994 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 167.172.56.36, server: www.xxxxx.co, request: "GET /wp-login.php HTT>2020/10/11 11:43:53 [crit] 20394#20394: *2149 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 18.162.245.185, server: www.xxxxx.co, request: "GET /wp-login.php HT>2020/10/11 13:16:09 [crit] 20394#20394: *2324 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.201, server: www.xxxxx.co, request: "GET /ads.txt HTTP/1.1>2020/10/11 13:41:01 [crit] 20394#20394: *2343 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 94.49.72.36, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstre>2020/10/11 13:50:54 [crit] 28196#28196: *1 connect() to unix:/var/run/php/php7.4-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 94.49.72.36, server: www.xxxxx.co, request: "GET / HTTP/1.1", upstream:>
【问题讨论】:
-
项目文件是否可以被nginx读取?
-
检查错误日志。你的 PHP
location块在哪里?为什么第二个server块监听端口 80? -
对于它的价值,这是我的一个工作 ssl confs pastebin.com/C4HpGvXP 的示例
-
@apokryfos 我用详细信息编辑问题
-
从
try_files中删除$uri/。看起来 nginx 在检查实际目录是否存在之前检查目录列表权限(可能)