IP address is shown instead of the Domain name - nginx

I just setup a AWS server and installed Nginx. I've also forwarded the public IP address to my Godaddy account. Typing the domain name on the address bar directs to the correct website but instead of seeing my domain name the public IP address is displayed.
I've followed the tutorial described here:
https://mediatemple.net/community/products/developer/204405534/install-nginx-on-ubuntu
I've done some modification in:
/etc/nginx/sites-available/example.com referencing /etc/nginx/sites-available/default
/etc/nginx/sites-available/example.com
server {
listen 80 default_server;
listen [::]:80;
server_name example.com www.example.com;
access_log /var/www/example.com/logs/access.log;
error_log /var/www/example.com/logs/error.log;
root /var/www/example.com;
index index.html;
}
The expected out should be the domain name is shown rather than the ip address.

Related

S3 virtual-host style nginx configuration for subdomains

I am trying to get a min.io server up and running with virtual-host style and am failing to configure nginx to do so correctly.
Expected result
bucket.s3.domain.com works to access bucket
Actual result
bucket.s3.domain.com is redirected to s3.domain.com/bucket – this does not generate virtual host style URLs.
My config (I omitted default port 80 to 443 redirect and other not relevant docker containers):
http {
upstream minio-s3 {
server 127.0.0.1:9000;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name s3.domain.com;
location / {
proxy_pass http://minio-s3;
}
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name "~^(?<subdomain>[^.]+).s3.domain.com";
location / {
proxy_pass http://127.0.0.1/$subdomain$request_uri;
proxy_set_header Host s3.domain.com;
}
}
Notes
Nginx running on Ubuntu Server LTS 20.04 (no Docker)
Min.io running on Docker port 9000
MINIO_DOMAIN is correctly set to s3.domain.com
bucket subdomain is correctly set
wildcard certificate for *.s3.domain.com is configured
Questions
How can I configure Min.io (besides passing env MINIO_DOMAIN) to use virtual host style URLs together with nginx?
How can I set up nginx to support this case?
So the answer to my original question is pretty simple:
Only one server block is needed, the subdomain regex is added to the server name and min.io resolves this correctly
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/s3.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/s3.domain.com/privkey.pem;
server_name "~^(?<subdomain>[^.]+).s3.domain.com" s3.domain.com;
location / {
proxy_pass http://minio-s3;
I hope this helps someone struggling with the same.
Virtual host in in short with Min.io:
Register domain, subdomain (per bucket)
Point domains all to your server (CNAME etc.)
Generate certificates with certbot (domain, wildcard for subdomains)
Launch min.io passing MINIO_DOMAIN as environment variable
Point all domains to Min.io application (domain and subdomains)

listen to specific port no working on nginx

The OS is Centos 7.3 , firewall is closed.
The server config on nginx is like.
server {
listen 2001;
listen [::]:2001;
server_name _;
root /usr/share/nginx/html;
index index.html;
}
I don't have a domain now, so the ip:port is what i want.
but when I typed xxx.xxx.xxx.xxx:2001 on the browser, can't access the page.
But the 80 port works fine.
I'm a new guy to both linux and nginx, any clue will help.

https works for local IP address but not for local IP with application port

I have Mattermost installed in my server, currently I can login to it by browsing through http://192.168.x.x:8066, I've installed a self-signed cerrtificate for this IP, but when I tried to browse it with https://192.168.x.x:8065, it failed to redirect to the Mattermost page.
Below is the configuration of my nginx.conf:
server {
listen 443 http2 ssl;
listen [::]:443 http2 ssl;
listen 443;
server_name 192.168.3.201:8066;
ssl on;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
}
However, when I just browse the URL without port 8066 , it displays the default nginx page with no errors.
What's wrong with my nginx.conf file? I'm still new to nginx FYI.
Any suggestions will be very much appreciated.
I suggest you follow the example nginx configuration from the documentation here. Start with that config file, updating server_name to be the domain name you want mattermost to be reachable from, and server to be the IP address and port on which mattermost is listening.
Once you've got that working, you can continue through the instructions to #9 which covers setting up SSL.

How to connect to another IP using NGINX

I am wondering how to connect to a different IP in Nginx that is different from localhost.
00.000.00.00
root
123456
note (the IP address and password indicated above are not realand will be replaced will actual)
Right now, this is what I have in Nginx config
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
By default nginx listens on all interfaces, that would be that listen 80; is equivalent to listen 0.0.0.0:80;. If you want nginx to listen only on localhost you should write listen 127.0.0.1:80; or listen localhost:80;, and if you want it to listen on some other interface you could do something like listen 152.168.0.30:80;.
On the other hand using the line server_name localhost; you are only accepting request directed to localhost in this block, and no the ones directed to your other IP's. To accept this request you can add server_name localhost 152.168.0.30 www.myweb.com; like a list or you could exclude this config so that the host IP isn't a restriction to accept or not a request.
For more information look in here.
Hope it helps!

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