NGINX site poxy_pass not working for non-www - nginx

I have a nodejs app (on port:8989) running on nginx and being routed to port 80.
server {
listen 80;
server_name example.com www.example.com;
access_log /var/log/nginx/example.access.log;
location / {
proxy_pass http://127.0.0.1:8989/;
}
}
www. addressess will load the website fine.
My current dns records are the following:
A Record # 108.xxx.xxx.xxx
A Record www 108.xxx.xxx.xxx
This server is running a very old version of nginx. (v0.7)

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)

Nginx proxy_pass rule Issue

So, I'm running some docker containers serving on ports 8090 and 8000. Now I want to setup Nginx reverse proxy to handle requests to both of these ports internally. The main URL http://milesblock.com changes automatically to http://milesblock.com/#/
I have setup a proxy_pass in nginx as follows-
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name milesblock.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8090;
}
location /api {
rewrite ^/api(.*) $1 break;
proxy_pass http://127.0.0.1:8000;
}
}
Now, the issue is because of the automatic change of the URL to http://milesblock.com/#/ the redirect to both the ports is not working as intended. Only the /api proxy is working with the above config file.
How do i configure the proxy to handle the traffic on port 8090 and also the api calls on port 8000?

why site is not redirecting with nginx

I am trying to redirect the domain example.com to another website example.blogspot.com (which is not hosted in my server).
I had been using htaccess and cpanel, so it was easy to redirect. But why redirect is not working in nginx.
No effects seen with following way in the version nginx/1.15.10 and latest vesta control panel,
Still showing the default page (index.html) generated by vesta control panel. Should I have to change in public_html ? Or restart server ?
I have edited nginx.conf with following code.
method 1
http{
server{
listen 80;
server_name example.com www.example.com;
return 301 https://example.blogspot.com$request_uri;
}
.....
}
method 2
http{
server{
listen [::]:80;
listen 80;
server_name example.com www.example.com;
return 301 https://example.blogspot.com$request_uri;
}
.....
}
method 3
http{
server {
server_name .example.com;
return 301 $scheme://example.blogspot.com;
}
....
}
restarting ngix after save
sudo service nginx restart
sudo systemctl restart nginx
Finally, adding Server Ip address with listen port redirect domain
http{
server{
listen my.server.ip.address:80;
server_name example.com www.example.com;
return 301 https://example.blogspot.com$request_uri;
}
.....
}

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.

nginx reverse proxy to different port on another server running Apache/WordPress

I am trying to setup nginx as a reverse proxy from one debian environment, to another debian environment. The two environments are on different IPs, and in different locations. Here is my configuration on the nginx reverse proxy.
server {
listen 80;
server_name foo.domain.com domain.com;
root /var/www;
if ($http_host != "foo.bar.com") {
rewrite ^ foo.bar.com$request_uri permanent;
}
index index.php index.html index.htm;
location / {
proxy_pass http://bar.domain.com:2000/;
proxy_redirect http://bar.domain.com http://foo.domain.com/;
}
}
Apache wordpress site is working on http://bar.domain.com:2000, however http://foo.domain.com does not transfer to it. When using foo.domain.com the address changes to foo.domain.com:2000 after it times out.

Resources