nginxに問題があります:サブドメインを追加しようとするまで問題なく動作しました。今、私は私のブラウザからPHPファイルを取得しようとするたびに、私は404エラーを取得します。しかし、私の主なドメインでは、それはまだ機能しているというのが最も奇妙なことです。 nginxにはエラーログはなく、アクセスログには404 HTTP応答が表示されます。誰かが答えを持っていますか?Nginxがphp criptsとサブドメインで404エラーを投げただけです
/etc/nginx/sites-available/domain.com
server {
listen 80;
server_name domain.com *.domain.com;
access_log /var/www/domain.com/logs/nginx_access.log vhosts;
error_log /var/www/domain.com/logs/nginx_error.log;
location/{
root /var/www/domain/www;
index index.php index.html index.htm;
}
error_page 500 501 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi.conf;
}
}
server {
listen 443 ssl http2;
server_name domain.com *.domain.com;
access_log /var/www/domain.com/logs/nginx_access.log vhosts;
error_log /var/www/domain.com/logs/nginx_error.log;
root /var/www/domain.com/www;
####### SSL Directives #######
ssl on;
ssl_certificate /var/www/domain.com/config/ssl/fullchain.domain.com.pem;
ssl_certificate_key /var/www/domain.com/config/ssl/privkey.domain.com.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA;
ssl_prefer_server_ciphers on;
location/{
root /var/www/domain.com/www;
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi.conf;
}
###
# Rewrite rules
###
###
# Rewrite rule 1 : redirect www.domain.com to domain.com
###
if ($host ~* ^www\.(.*)domain\.com$) {
rewrite ^(.*) //domain.com/$1 permanent;
}
}
server {
listen 443 ssl;
server_name sub.domain.com;
location/{
root /var/www/domain.com/sub/www;
index index.php index.html index.htm;
}
###
# SSL
###
ssl on;
ssl_certificate /var/www/domain.com/config/ssl/fullchain.sub.domain.com.pem;
ssl_certificate_key /var/www/domain.com/config/ssl/privkey.sub.domain.com.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES25$;
ssl_prefer_server_ciphers on;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi.conf;
}
###
# Logging
###
access_log /var/www/domain.com/logs/nginx_access.log vhosts;
error_log /var/www/domain.com/logs/nginx_error.log;
}
server {
listen 80;
server_name sub.domain.com;
location/{
root /var/www/domain.com/sub/www;
index index.php index.html index.htm;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi.conf;
}
###
# Logging
###
access_log /var/www/domain.com/logs/nginx_access.log vhosts;
error_log /var/www/domain.com/logs/nginx_error.log;
}
エラーログの最後の2行
2017/11/26 15:44:37 [error] 25444#25444: *10 directory index of "/var/www/domain.com/sub/www/files/" is forbidden, client: 00.00.000.000, server: sub.domain.com, request: "GET /files/ HTTP/2.0", host: "sub.domain.com"
2017/11/26 15:46:10 [error] 25444#25444: *14 open() "/var/www/domain.com/sub/www/this_file_does_not_exist.p" failed (2: No such file or directory), client: 00.00.000.000, server: sub.domain.com, request: "GET /this_file_does_not_exist.p HTTP/2.0", host: "sub.domain.com"
正常に動作しているようだ:それは返しますインデックスなしのフォルダにアクセスしようとすると403は禁止され、存在しないファイルを取得しようとすると404が表示されます。しかし、ここでは約404のPHPファイルについては、要求された場合でも注意しています。メインドメインでのaccess.log
domain.com 00.00.000.000 - - [26/Nov/2017:15:45:32 +0100] "GET /index.php HTTP/2.0" 200 176 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
sub.domain.com 00.00.000.000 - - [26/Nov/2017:15:45:42 +0100] "GET /index.php HTTP/2.0" 404 261 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
sub.domain.com 00.00.000.000 - - [26/Nov/2017:15:46:10 +0100] "GET /this_file_does_not_exist.p HTTP/2.0" 404 260 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
sub.domain.com 00.00.000.000 - - [26/Nov/2017:15:46:24 +0100] "GET /main_style.css HTTP/2.0" 200 2931 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
の
最後の行は、PHPファイルは200応答を持っているし、ブラウザに表示されます。しかし、サブドメインでは、彼らはここにいないのと同じように404応答を返します。しかし、index.phpはmain_style.cssと同じフォルダにあり、main_style.cssは200応答を返して表示されます。
私は本当にこれが動作するために何をすべきか分かりません。もし誰かが彼が大歓迎されるのを助けることができたら。
EDIT:これは、hurl.itでhttps://sub.domain.com/を取得しようとしたときのHTTP応答です。 enter image description here
PS:sub.domain.comは私のドメイン名ではありません。私はちょうどGoogleの私のウェブサイトの上にあるこの投稿を避けるためにそれを変更しました。