Reputation: 62404
http://localhost is showing a 404 by nginx 1.13. When I look at the container logs I can see that nginx isn't passing the request off to php-fpm but is instead looking for an index.html. I can't figure out why it won't pass the request to php-fpm.
/etc/nginx/conf.d/default.conf
I've verified this file is loaded.
server {
listen 80;
root /var/www/html/public;
index index.php;
charset utf-8;
# look for local files on the container before sending the request to fpm
location / {
try_files $uri /index.php?$query_string;
}
# nothing local, let fpm handle it
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
# Httpoxy exploit (https://httpoxy.org/) fix
fastcgi_param HTTP_PROXY "";
# allow larger POSTS for handling stripe payment tokens
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}
Process list within the web container:
PID USER TIME COMMAND
1 root 0:00 s6-svscan -t0 /var/run/s6/services
33 root 0:00 s6-supervise s6-fdholderd
170 root 0:00 s6-supervise php-fpm
171 root 0:00 s6-supervise nginx
173 root 0:00 php-fpm: master process (/usr/local/etc/php-fpm.conf)
174 root 0:00 {run} /bin/sh ./run
177 root 0:00 nginx: master process nginx -g daemon off;
187 nginx 0:00 nginx: worker process
192 www-data 0:00 php-fpm: pool www
193 www-data 0:00 php-fpm: pool www
194 root 0:00 ps -ef
Container logs
web_1 | 2017/05/13 06:13:10 [error] 187#187: *1 "/etc/nginx/html/index.html" is not found (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", host: "mysite.local"
web_1 | 172.19.0.1 - - [13/May/2017:06:13:10 +0000] "GET / HTTP/1.1" 404 571 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36"
Update Removed all references to index.htm per a few of the below comments
Upvotes: 5
Views: 32440
Reputation: 19
This issue is also happening as follows.
When you host several sites on the same IP, you have the directives
listen example.com:80
server_name example.com
...
listen example2.com:80
server_name example2.com
But, a malware code on the internet keep scanning the network to find a possible vector of attack to your site. Namely, security scanners try to connect to your site using IP address, not the domain name. You do not have the default configuration for the bare IP address. Hence the error comes out.
when you configure the server to respond with the proper web page to this malicious request to the http://IP_ADDRESS, the bunch of additional hack attempts will follow. Namely, hackers will attempt to detect your CMS suite installed on the server, and will exploit their bugs.
With this being said, the way how nginx responds to this malicius request ('404 Not found') seems to be perfectly OK.
Upvotes: 0
Reputation: 62404
The problem was that despite my own vhosts configuration being in /etc/nginx/conf.d/default.conf
, nginx -T
(which shows nginx's loaded configuration) didn't show the file having been read.
The include /etc/nginx/conf.d/*.conf;
directive was missing from my nginx.conf
.
Upvotes: 0
Reputation: 1684
By default, all of config files in /etc/nginx/conf.d/
folder, including your file here /etc/nginx/conf.d/default.conf
, are extended from /etc/nginx/nginx.conf
.
In this config you did not specify index
directive in server {}
block. Then nginx will lookup the default in /etc/nginx/nginx.conf
.
Solution for this is override the default:
server {
listen 80;
root /var/www/html/public;
charset utf-8;
index index.php index.html index.htm;
}
Then reset your nginx: sudo service nginx restart
Then index.php
will have higher priority than the rest for nginx to lookup.
Upvotes: 3
Reputation: 49722
nginx
is using the default value for the index
directive to process the URI /
(as the directory does indeed exist).
You should add an explicit index
statement to your server
block.
server {
...
index index.php;
location / {
try_files $uri /index.php?$query_string;
}
# nothing local, let fpm handle it
location ~ [^/]\.php(/|$) {
...
}
}
See this document for more.
Upvotes: 1