A
A
Alexander2020-11-30 23:08:19
Nginx
Alexander, 2020-11-30 23:08:19

How to generate nginx config?

4 hours went by as I try to write the nginx config correctly. Help me, please, otherwise I'll go crazy ...

server {
     listen 80;
     server_name domain.ru;
     return 301 https://$host$request_uri;
}
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name _;
        allow all;
        auth_basic off;
        root /var/www/html;

        index index.php index.html index.htm index.nginx-debian.html;

}
server {
        listen 8002 default_server;
        ssl                     on;
        ssl_certificate         /etc/letsencrypt/live/domain.ru/fullchain.pem;
        ssl_certificate_key     /etc/letsencrypt/live/domain.ru/privkey.pem;

        server_name _;

        location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
         }
}
server {
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name domain.ru;

        satisfy all;
        auth_basic           "Please Log-In";
        auth_basic_user_file /etc/nginx/.htpasswd;

        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/domain.ru/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/domain.ru/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}


The task is this: if the entrance is from external domain.ru - then redirect to https and request basic authorization, if from LAN - no redirect and no authorization ...
PS I want to cry from nginx =(

Answer the question

In order to leave comments, you need to log in

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

server {
 listen local.ip;

  тут конфиг без авторизации
}

server {
  listen external.ip;

  тут конфиг с авторизацией
}

You can, of course, do it tricky with satisfy allrouting to different locations - but if you don’t like it, it’s straight, like a spear shaft.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question