I have the following server block:
server {
listen 80 default_server;
server_name _;
return 308 https://$http_host$request_uri;
}
however when accessing the url http://localhost/coletor
a 404 error appears and while accessing through https the url loads correctly. What am I doing wrong?
access.log:
2022/09/01 17:04:27 [error] 26#26: *3 open() "/usr/share/nginx/html/coletor" failed (2: No such file or directory), client: 172.27.0.1, server: localhost, request: "GET /coletor HTTP/1.1", host: "localhost"
172.27.0.1 - - [01/Sep/2022:17:04:27 0000] "GET /coletor HTTP/1.1" 404 187 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
My entire nginx.conf:
user 'www-data';
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 3600;
proxy_read_timeout 3600;
proxy_connect_timeout 3600;
proxy_send_timeout 3600;
send_timeout 3600;
client_body_timeout 3600;
lingering_timeout 3600;
resolver_timeout 3600;
fastcgi_connect_timeout 3600;
fastcgi_read_timeout 3600;
fastcgi_send_timeout 3600;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers HIGH:!aNULL:!MD5;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log notice;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
client_max_body_size 200M;
map $cookie_version $version_cookie_host {
include /etc/nginx/versions/*.conf;
}
map $http_app_version $version_header_host {
include /etc/nginx/versions/*.conf;
}
server {
listen 80 default_server;
server_name _;
return 308 https://$http_host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/ssl/nexello.crt;
ssl_certificate_key /etc/ssl/nexello.key;
server_name _;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
set $auth_host 172.17.0.1;
charset utf-8;
location / {
if ($request_uri ~ .*coletor.*) {
proxy_pass https://$version_cookie_host;
}
if ($cookie_token) {
proxy_pass https://$version_cookie_host;
}
if ($http_authorization) {
proxy_pass https://$version_header_host;
}
if ($request_uri ~ .*/auth/.*) {
proxy_pass https://$auth_host:7001;
}
proxy_pass https://$auth_host:7001;
}
}
}
CodePudding user response:
Your error message contains server: localhost
- which is referring to the value of server_name
in the server
block causing the error.
The server
blocks in your question all contain server_name _;
- so there must be another server
block hidden in an included file.
Use nginx -T
(uppercase T
) to view the entire Nginx configuration across all included files.