How nginx workers listen to the same port - nginx

After going through nginx documentation, I saw that in their tutorial they make two server blocks as following:
server {
listen 192.168.1.1:80
server_name example.org www.example.org;
}
server {
listen 192.168.1.1:80
server_name example.net www.example.net;
}

Both domains point to the ip 192.168.1.1, for this in the 2 domains you set the dns record type A, example:
www.example.org A 192.168.1.1
www.example.net A 192.168.1.1
The server nginx only thing it does is serve on port 80 for any domain and shows the same page.

Related

can not connect zammad remotely, outside

I have installed zammad on ubuntu 20.4,
I can open zammad with localhost address but can not connect to zammad from remote with server IP address
I have edited the file /etc/nginx/sites-available/zammad.conf
#
# this is the nginx config for zammad
#
upstream zammad-railsserver {
server 127.0.0.1:3000;
}
upstream zammad-websocket {
server 127.0.0.1:6042;
}
server {
listen 80;
listen [::]:80;
# replace 'localhost' with your fqdn if you want to use zammad from remote
#server_name localhost;
server_name 10.20.60.200;
# security - prevent information disclosure about server version
#server_tokens off;
root /opt/zammad/public;
access_log /var/log/nginx/zammad.access.log;
error_log /var/log/nginx/zammad.error.log;
client_max_body_size 50M;
for server_name I have put my IP adress, and with this IP address can not connect to zammad, but with 127.0.0.1:3000 it is connecting
can anyone help on thi, please?
Give in the URL 10.20.60.200:3000. It is enough, when you just only give the IP adress without port into the URL.

Configuring Nginx - routing traffic from HTTP to HTTPS and BAD REQUEST error (local host, no domain)

I'm trying to configure my Nginx in a way so that all HTTP requests are redirected to HTTPS. This is a testing environment and I don't have the domain, hence, I'm not sure whether the redirect can function properly. The host part is simply 127.0.0.1. This is the current configuration:
server {
listen 80;
listen [::]:80;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name _;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
...
I also tried:
removing server_name _;
putting the return 301 in a location block;
adding further ssl settings, such as ssl_session_timeout, ssl_protocols, ssl_prefer_server_ciphers.
ssl on has been removed.
The syntax has been tested, nginx reloaded, the ports have been tested with nmap (both 80 and 443 are open).
When I curl -k (since the certificate is self-signed) 127.0.0.1 I get this message:
301 Moved Permanently
nginx/1.14.0 (Ubuntu)
When I curl -k 127.0.0.1:443 I get this message:
400 The plain HTTP request was sent to HTTPS port 400 Bad Request The
plain HTTP request was sent to HTTPS port nginx/1.14.0 (Ubuntu)
Could someone help me to understand what am I doing wrong? I'd be happy to provide more information. Thank you so much!!
So here is an nginx config that is working for me.
upstream app {
server app:8080;
}
server {
listen 80;
listen [::]:80;
server_name webprojects-dev.co.uk;
return 301 https://webprojects-dev.co.uk$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 http2;
server_name webprojects-dev.co.uk;
include /etc/nginx/common.conf;
include /etc/nginx/ssl.conf;
location / {
proxy_pass http://app;
include /etc/nginx/common_location.conf;
}
}
In this instance nginx is running in a stack of docker containers networked with docker compose but that shouldnt have any bearing on how it works.
The upstream is the app container (and port) for a reverse proxy.
The first server block is forwarding on requests to https. As you can see the main difference between mine and yours is the server_name is the domain name and is also included in the return 301 statement.
The second server block is for https. Again server_name is a domain but other than that the only other difference I can see is I don't have ssl on the line listen [::]:443.
Disclaimer: Not an expert on nginx. I just hacked away till I had a reverse proxy config that works for me and now I just copy and paste it for everything.

Nginx win server 2012 - Configure proxy pass

I have a node server listening on localhost:8080 and I'd like to use nginx as proxy pass, so i made nginx listen to port 80 incoming connections. However I'm not able to configure nginx config to do the reverse proxying. I do not currently have a domain, only server IP. So I'm guessing server_name has to be set to $host or something?
events{
}
http{
server{
listen 80;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host 127.0.0.1;
}
}
}
If I try to visit my server IP on port 80 I just receive welcome to Nginx page.
You should reload and restart your nginx
sudo service nginx reload
sudo service nginx restart

Port redirection for domain

I have NGINX on my VPS working on port 80 (few domains on it), and I want add GlassFish on port 8080.
Next I want add domain for GlassFish, but on domain it should work on port 80.
How I can do that?
Him add server rule, for example:
server {
listen 80;
server_name demo.glass.fish;
location / {
proxy_pass http://localhost:8080;
}
}

How to configure nginx so that the web server only allow access via IP address and deny all access via domain name?

Suppose I have a web server running on the IP address 1.2.3.4 and the domain name abc.com resolves to 1.2.3.4. How shall I write the nginx.conf so that the web server only allows access via the IP address 1.2.3.4 and denies all access via the domain name abc.com?
nginx.conf:
http {
...
server {
listen 80;
server_name 1.2.3.4;
}
...
}
Currently I set server_name to 1.2.3.4, and it seems that the web server is accessible via both 1.2.3.4 and abc.com.
I would define two server stanzas. One for abc.com to which access is denied. Then define a catch-all server that can be accessed via ip address:
server {
listen 80;
server_name abc.com;
return 403;
}
server {
listen 80 default_server;
server_name _;
}

Resources