R
R
Ruslan2020-12-29 12:47:19
Nginx
Ruslan, 2020-12-29 12:47:19

How to set up a site on nginx behind nat?

I don’t understand this topic well, but there was a need to configure it. Maybe somewhere I will not express myself correctly:

Bought a white ip - aaaa
Bought a domain name - name.ua
There is a server with nginx, with ip - bbbb, on which the site is located.
There is nat in front of nginx.
From nat to the server with nging, ports 80 and 443
are forwarded. On ping aaaa, the router (nat) answers.

It is impossible to access the site from the Internet not by aaaa, not by name.ua.
On an internal network through bbbb the site works.
What settings are needed on nginx?

nginx.conf:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    include /etc/nginx/conf.d/*.conf;
server {
       listen 80;
       server_name name.ua;

        location = /favicon.ico {
            alias  /home/siteadmin/cabinet_front_end/favicon.ico;
        }

        location / {
            root /home/user/name_front_end;
            try_files $uri $uri/ /index.html;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2020-12-29
@ky0

If the ports are forwarded and the domain has an A-record pointing to the white address of the router, everything should work.
What error are you getting when you try to connect? Do you see anything in the logs? By the way, are you trying to get to the site at an external address from inside the same network - this will not always work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question