#php #linux #laravel #nginx
#php #linux #laravel #nginx
Вопрос:
Я перепробовал много ответов с SO и других сайтов в Интернете, но, похоже, я не могу заставить его работать.
Я получаю запрещенную ошибку 403 при развертывании моего проекта laravel с конфигурацией nginx:
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:>
Комментарии:
1. доступны ли файлы проекта для чтения с помощью nginx?
2. Проверьте журнал ошибок. Где ваш PHP
location
-блок? Почему второйserver
блок прослушивает порт 80?3. Как бы то ни было, вот пример одной из моих рабочих SSL-конференций pastebin.com/C4HpGvXP
4. @apokryfos Я редактирую вопрос с подробностями
5. Удалить
$uri/
изtry_files
. Похоже, что nginx проверяет разрешения на список каталогов, прежде чем проверять, существует ли фактический каталог (возможно)
Ответ №1:
Наконец-то исправлено. Комментарий от @Ivan Shatsky заставил меня искать информацию о PHP-FPM. Я обнаружил, что это важно, и большинство примеров в Интернете не включали его в конфигурацию. Я установил его через:
sudo apt-get update
sudo apt-get install php7.4-cli php7.4-curl php7.4-mysql php7.4-fpm php7.4-gd php7.4-xml php7.4-mbstring php7.4-zip php7.4-soap php7.4-dev -y
Я столкнулся с другими проблемами, но, наконец, заставил его работать с этой конфигурацией:
server {
listen 80;
server_name www.xxxxx.co xxxxx.co;
return 301 https://www.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
server_name www.xxxxx.co xxxxx.co;
root /var/www/www.xxxxx.co/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# pass the PHP scripts to FastCGI server listening on /var/run/php7.4-fpm.sock
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}