4

I have setup a nginx web server with uwsgi to host my flask app. When I access it through the LAN ip (192.168.1.x) I get the website just fine but when I access it through my public IP i am greeted with "404 Not Found nginx/1.14.0 (Ubuntu)". Why is this? How can I fix it?

/etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

sites-available

server {
    listen 80;
    server_name 192.168.1.108;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
    }
}

project.ini

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = myproject.sock
chmod-socket = 660
vacuum = true

die-on-term = true
david doyyer 32
  • 43
  • 1
  • 1
  • 4

2 Answers2

2

You specifically asked for your web site to only answer to the RFC1918 IP:

    server_name 192.168.1.108;

Your global IP address isn't 192.168.1.108, so it will never match this server block, and thus will be served by the default server block.

To solve the problem, buy a domain name, set an address record for a name in your domain, and then set the server_name to that name.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • @Ritwik Hi, this is a site for professional IT and we don't support running web sites on home networks. – Michael Hampton Sep 21 '20 at 15:11
  • hello, actually I have my lab server where I need to deploy my website. Before I do that, I was just testing it on my home. The lab server is running on the university intranet. I connect using SSH. Unlike ngrok, nginx doesn't give me a public address (neither IP nor domain). So I just want to know how can I deploy using nginx? – Ritwik Sep 21 '20 at 15:22
0

We have here 3 Possibilities - depends on your later need

Option One:

/etc/nginx/sites-enabled/optionone

server {
listen 80;
server_name 192.168.1.108 1.2.3.4;

location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
}
}

All in One, easy to Read

option two

/etc/nginx/sites-avaible/optiontwo

server {
listen 80;
server_name 192.168.1.108;

location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
}
}
server {
listen 80;
server_name 1.2.3.4;

location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
}
}

Also easy to Read but splits it in 2 seperate instances, comfortable to debug

and

option three

/etc/nginx/sites-enabled/option-three-int

server {
listen 80;
server_name 192.168.1.108;

location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
}
}

/etc/nginx/sites-enabled/option-three-pub

server {
listen 80;
server_name 1.2.3.4;

location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/matthew/myproject/myproject.sock;
}
}

Each Site gets its own file, nice to handle later i.e. for certbot and reaaaly easy to read later and know which file do what.

As you can see, this can be done on more as one way -each has its "do's and do not's"

Reminder:

Dont forget to activate (link) the site to sites-enabled

djdomi
  • 1,377
  • 3
  • 10
  • 19