0

I was following the nginx,uwsgi with flask & docker tutorial. My nginx config file contains:

server {

listen 5000;
server_name 19X.X.X.X;

client_header_buffer_size 5M;
large_client_header_buffers 4 5M;
client_max_body_size 75M;

location / {
    include uwsgi_params;     
    uwsgi_pass flask:8080;
   }
}

Here I want to add an additional IP address like 123.345.67.8 and a subdomain test.mydomain.com. How can I add there?

EDIT 2:


server {

listen 1.1.1.1:5000 default_server;
server_name localhost;

client_header_buffer_size 5M;
large_client_header_buffers 4 5M;
client_max_body_size 75M;

location / {
    include uwsgi_params;     
    uwsgi_pass flask:8080;
   }
}


server {

listen 2.2.2.2:5000 default_server;
server_name test.mydomain.com;

client_header_buffer_size 5M;
large_client_header_buffers 4 5M;
client_max_body_size 75M;

location / {
    include uwsgi_params;     
    uwsgi_pass flask:8080;
   }
}
siam
  • 1
  • 1
  • You can list any number of server names with the `server_name` directive. However having only one server block like this, nginx will use it to process every request coming to the TCP port 5000 no matter what IP address it come to or what is the HTTP `Host` header value. See the [How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html) official documentation page or [this](https://stackoverflow.com/a/60362700/7121513) answer for even more details. – Ivan Shatsky Feb 15 '22 at 12:47
  • @IvanShatsky Thanks for your reply. Please see the EDIT1 of my question. If I do so then can I access it with "1.1.1.1:5000" as well as "test.mydomain.com" ? – siam Feb 15 '22 at 12:59
  • I think you didn't got an idea about the **default server**. If your server listens on both `1.1.1.1` and `2.2.2.2` IP addresses, your first server block will server every request coming to the port 5000. You don't need to define the second server block. You'll need it only if you want to serve different sites on `1.1.1.1` and `2.2.2.2`. And using `test.mydomain.com` in the browser adddress bar will made the browser to use 80/443 port depending on `htttp://` or `https://` scheme, you'll need to explicitly specify the port: `http://test.mydomain.com:5000/...` – Ivan Shatsky Feb 15 '22 at 13:34
  • @IvanShatsky That's a clear idea about the default server. Thanks. But let me clarify one issue. For example, I want to add 1.1.1.1 IP which works for private network access. And want to add 2.2.2.2 -> https://test.mydomain.com for accessing it publicly. Then how can I modify for this issue? – siam Feb 15 '22 at 14:11
  • Please see the EDIT 2 (updated) is it going to work now ? – siam Feb 15 '22 at 14:18
  • From my understanding, if you want to serve the same site for both addresses, you don't need anything other than a single server block with the `listen 5000;` directive. You don't need to even specify a server name if your `test.mydomain.com` domain resolves to your address. It will serve any request coming to the TCP port 5000. I think the links I provide earlier are quite explainable. – Ivan Shatsky Feb 15 '22 at 17:29

0 Answers0