Score:0

nginx different name for different port

pk flag

I have two web applications (webapp1 port 7000 & webapp2 port 8000) for internal use hosted on my server VM with IP address 192.168.15.10 (ubuntu 20.04)

I want to see if it is possible to assign different names for the two web applications.

How I want things to work is:

If an internal user enters webapp1.random-company.com in the browser, it will direct the user to webapp1 with port 7000 (192.168.15.10:7000)

If an internal user enters webapp2.random-company.com in the browser, it will direct the user to webapp2 with port 8000 (192.168.15.10:8000)

I tried using nginx on 192.168.15.10 and was able to direct users to webapp1.random-company.com (192.168.15.10:7000). However, I failed to direct users to webapp2.random-company. In fact, when an user types webapp1.random-company.com:8000, it directs the user to webapp2.

Is this something that is possible?

One application is built in django and the other one is built in flask

Score:0
cn flag

Don't address ports in URLs, the power of nginx is its reverse proxy capability.

First, create different config files for each web application, do not just smash everything in one server configuration - or even worse, in the nginx.conf file. Set an upstream above your main server block for each application:

upstream webapp1 {
    server 127.0.0.1:7000 weight=1 fail_timeout=0;  #the timeout and weight settings are optional
    }

Inside the server blocks, when nginx accesses the location "/", call the upstream:

server {
        listen 443 ssl http2; #if you go with HTTPS - which you should
        server_name webapp1.random-company.com;
[...]

location / {
        [...]
        proxy_pass http://webapp1;
    }

Repeat for webapp2 accordingly:

upstream webapp2 {
    server 127.0.0.1:8000;
    }

server {
        listen 443 ssl http2; #if you go with HTTPS - which you should
        server_name webapp2.random-company.com;
        [...]

location / {
        [...]
        proxy_pass http://webapp2;
    }

Concerning the Django / Flask applications, you don't actually need to call the applications via TCP/IP, you could have nginx directly listen to their UNIX sockets. What do you use to deliver the application? uWSGI, Gunicorn, (...)?

Further reading for Flask on uWSGI

In general this is not necessarily an Ubuntu topic, perhaps you would want to check StackOverflow or Serverfault instead.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.