nginx not responding to GET requests - nginx

nginx is not responding to any requests and I'm not sure why. Here is what my file in sites-available looks like (it is symlinked from sites-available):
server {
listen 80;
server_name 127.0.0.1;
access_log /srv/www/logs/access_log;
error_log /srv/www/logs/error_log;
root /srv/www/public_html;
location / {
index index.html;
}
}
If I try to access 127.0.0.1 or localhost, the browser (Firefox) just tells me that is "loading" for a very long time.
Nginx is listening on port 80 when I run netstat -lpn:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10952/nginx
I have tried to telnet 127.0.0.1 80 and then typed the following:
GET /index.html HTTP/1.1
Host: 79.124.59.177
<blank line>
However, there is no response to this. Any ideas or suggestions? I'm completely stumped.

I think you should modify Host as "127.0.0.1", which represent the name of server, and it should same as server_name in config file, I guess.

Related

How to make nginx process only the specified host (alocal, blocal), but ignore the "naked" ip address?

I have two rules for nginx (local):
server_name alocal;
listen 80;
location / {
...
proxy_pass http://localhost:8081;
}
and
server_name blocal;
listen 80;
location / {
...
proxy_pass http://localhost:8082;
}
I also changed the "hosts" file.
C:\Windows\System32\Drivers\etc\hosts
127.0.0.1 alocal
127.0.0.1 blocal
Everything works well. When I make a request through the browser, I get the expected behavior.
http://alocal -> http://127.0.0.1:8081
http://blocal -> http://127.0.0.1:8082
But when I specify just "localhost" as a host, nginx still processes my request, and it takes the first rule that comes along (from those that I gave above).
http://localhost -> http://127.0.0.1:8081
or (depends on which rule comes first)
http://localhost -> http://127.0.0.1:8082
Why does nginx process localhost if other hosts (alocal, blocal) are specified in server_name?
How to make nginx process only the specified host (alocal, blocal), but ignore the "naked" ip address?
Nginx listening to Port 80. If there is a request not matching any server_name the default is taken. Either given by listen 80 default_server; or the first entry if omitted.
If you want to block all requests not matching the specified server_name or with empty Host-Header you need a catch all as last block:
server {
listen 80 default_server;
server_name "";
return 444;
}
It will be not really ignored, but rejected. You can't "ignore" something, nginx is blocking port 80 and handling all requests somehow.

Nginx proxy conf for minecraft not working

Hi I am trying to get a nginx conf working with minecraft.
I created several subdomains (A-records) and I want to use only the subdomains (without port).
Therefore I installed nginx (stable release) on CentOS 7.
Added portforward in my router on 25565 to this VM (fixed IP) and added 25565 (tcp, permanent) to the firewall. Testing nginx with default ip (port 80) => Welcome to nginx....
Testing port 25565 (with minecraft) also works.
Left nginx.conf and default.conf intact (no changes) and added my minecraft.conf in /etc/nginx/conf.d/
Minecraft uses tcp protocol (I asume this is supported by nginx) and listens default to 25565 that's why I run my instances on 25566 and 25567
As far as I understood main directives like http(s), stream etc. should be declared in nginx.conf
It's not posible to declare a stream in the minecraft.conf (in ./conf.d/)
Also not possible to proxy_pass to the upstream (directive proxy_pass not allowed here)
(I can use location / { http://..} but that's not tcp)
What do I miss to make it work as I want to use a proxy (Network Solutions does not allow SRV records for subdomains)
my minecraft.conf:
upstream mcserver1 {
server 192.168.1.14:25566;
}
upstream mcserver2 {
server 192.168.1.14:25567;
}
server {
listen 25565;
server_name camelot.xyz.net;
access_log /var/log/nginx/mcs1.access;
error_log /var/log/nginx/mcs1.error;
proxy_pass mcserver1;
}
server {
listen 25565;
server_name cityworld.xyz.net;
access_log /var/log/nginx/mcs2.access;
error_log /var/log/nginx/mcs2.error;
proxy_pass mcserver2;
}
In the default error.log I find
2021/04/11 21:37:12 [notice] 5525#5525: signal process started
2021/04/11 21:37:12 [emerg] 2325#2325: bind() to 0.0.0.0:25565 failed (98: Address already in use)
2021/04/11 21:37:12 [emerg] 2325#2325: still could not bind()

Using proxy_pass to forward http requests based on headers

I'm using a combination of ip6tables and nginx to process http requests from clients. The nginx server listens on port 8081 and must forward a request after examining the header.
Clients can send two types of requests:
GET/POST with no headers. These should be re-directed to https://jaguar.mydomain.com
GET/POST with specific header elb-jaguar.mydomain.com. These should be redirected to https://elb-jaguar.mydomain.com
When run as nginx -c /home/build/v6-only.conf, nginx fails because one server{} directive already has listen on port 8081
nginx: [emerg] duplicate listen options for [::]:8081 in /etc/nginx/v6/v6-only.conf:13
My config is as below:
server {
listen [::]:8081 ssl ipv6only=on;
server_name elb-jaguar.mydomain.com;
ssl_certificate /etc/ssl/elb.crt;
ssl_certificate_key /etc/ssl/elb.key;
location / {
proxy_pass https://elb-jaguar.mydomain.com:443;
}
}
server {
listen [::]:8081 ssl ipv6only=on;
ssl_certificate /etc/ssl/regular.crt;
ssl_certificate_key /etc/ssl/regular.key;
server_name jaguar.mydomain.com;
location / {
proxy_pass https://jaguar.mydomain.com:443;
}
}
How can I fix the above config to get the desired forwarding with proxy_pass?
Difficult to see because that setup should work.
But looking closer at the NGINX docs and your need for IPv6 only, it says (my emphasis):
ipv6only=on|off
this parameter (0.7.42) determines (via the IPV6_V6ONLY socket option) whether an IPv6 socket listening on a wildcard address [::] will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start.
Because the error message complains of 'duplicate listen options', not 'already listening on that port' or similar, it suggests it is complaining about trying to set ipv6only a second time (even to the same value).
Also, it does say This parameter is turned on by default, so you could easily just remove it altogether, if only to try it.

configuring multiple domains with nginx

First of all there's already a server running on 80 port(with domain, let's say domainA.com ), and I have another domain(domainB.com). Here's what I'm trying to do.
80 port: domainA.com
3000 port: domainB.com
so If I make a request to domainB.com It shouldn't redirect to domainA.com:3000 but should actually works on the same server. and DNS server ip is set to the server as the same as domainA.com is connected to (so if I go to domainB.com it just redirects to domainA.com, I think I need to fix this part but I have no idea). how can I make this happen?
server {
listen 80;
server_name domainA.com;
root /var/www/domainA;
}
server {
listen 3000;
server_name domainB.com ;
root /var/www/domainB;
}
you now can access this sites via : domainA.com and domainB.com:333
also you can make both of them listen on port 80 :
nginx can detect that request is coming for which domain and redirect request to that domain :
server {
listen 80;
server_name domainA.com;
root /var/www/domainA;
}
server {
listen 80;
server_name domainB.com ;
root /var/www/domainB;
}
see this : nginx server_names
source : diffrent domain on same ip

Nginx – Multiple Sites one VPS - Correct Configuration?

I don’t really know anything about this but I’ve done a bit of reading. If I point my two domains to the VPS nameservers, and my app-nginx.conf looks like this:
server {
listen 80;
server_name www.domain1.com;
root /path/to/your/project;
}
server {
listen 80;
server_name www.domain2.com;
root /path/to/your/project;
}
Is there anything else I would need to be doing? It doesn’t seem to work currently.
please try on server:
telnet localhost 80
GET / HTTP/1.1
Host: www.domain2.com
<double ENTER>
What you see now?
What you see in logs, when nginx start?
What is output of nginx -T ?

Resources