Jump to content

Nginx reverse proxy configuration

Cruorzy

Hey guys i have asked this question previously on a other section, but im still hopeless.

 

I have this nginx server running for all 80 and 443 traffic, i have 2 domain names and the configuration is set as following.

www.example.com goes to the right server

www.projects.com goes to the right server

 

BUT

phpmyadmin.example.com

phpmyadmin.projects.com

Both goes to the www.example.com server.

 

Here are the config files.

 

server {
    listen       443 ssl;
    server_name  example.com www.example.com;
	
	##SSL STUFF

    location / {
        proxy_pass http://192.168.0.110:80;
    }
}

server {
    listen       443 ssl;
    server_name  projects.com www.projects.com;
	
	##SSL STUFF

    location / {
        proxy_pass http://192.168.0.120:80;
    }
}

server {
    listen       443 ssl;
    server_name  phpmyadmin.example.com;
	
	##SSL STUFF

    location / {
        proxy_pass http://192.168.0.130:80;
    }
}

server {
    listen       443 ssl;
    server_name  phpmyadmin.projects.com;
	
	##SSL STUFF

    location / {
        proxy_pass http://192.168.0.140:80;
    }
}

 

And the default.conf that will set all 80 traffic to 443

 

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location ~ /.well-known {
        allow all;
        root   /usr/share/nginx/html;
    }

    return 307 https://$host$request_uri;
}

 

Thanks in advance.

 

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

@AlexTheRose

 

Well the server is being hosted by a dedicated hosting service, that is not really important.

I use Docker that is a piece of software for linux virtualization (like vmWare) <--- This is massively simplified

 

This is the structute

Containers are like Different VM's. The proxy is running Nginx were the problem is actually located.

 

The other containers are webservers i run, like PhpMyAdmin, Gogs, Owncloud/Nextcloud

 

dockercontainersstructure.png

 

Outer border is the actual machine the box in there is Docker, in there are docker containers.

They can all communicate with each other by a virtual network i created. (Docker is awesome btw, if you dont know it you should take a look)

 

I did troubleshoot yesterday a bit and i seem to get it to work with making default.conf like this

 

server {
    listen       80 default;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location ~ /.well-known {
        allow all;
        root   /usr/share/nginx/html;
    }

    return 307 https://$host$request_uri;
}

But then again, if i wanted to connect to my 3rd domain that is NOT anywere in ANY config, it will still proceed to www.example.com his container,

I find this strange since the configs are domain specific and shouldn't count for domains that do not appear in the config.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Did you make sure to clear your cache? Might have something cached here, looks alright to me.

// TODO: Update signature to include PC buid.

Link to comment
Share on other sites

Link to post
Share on other sites

@TheGuyNL It is not cache, but it works now.

 

Anyways when i go to a subdomain that is not added to a configuration. it still wants to go to www.example.com. I0 find this strange since it not set to default.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

It works now properly with a default configuration set to a return, so when the domain is not listed in a configuration it will give a temporary http return to the a main website i have running.

 

Still not 100% i wanted, but it will do for now.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Cruorzy said:

It works now properly with a default configuration set to a return, so when the domain is not listed in a configuration it will give a temporary http return to the a main website i have running.

 

Still not 100% i wanted, but it will do for now.

Might want to use *.example.com to catch all non-configures subdomains and put a 302 on there.

// TODO: Update signature to include PC buid.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, TheGuyNL said:

Might want to use *.example.com to catch all non-configures subdomains and put a 302 on there.

Thanks, but the default works great atm.

Maybe ill play with it a bit later when my Docker containers are setup correctly.

Quote or mention me if not feel ignored 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×