Proxy reverso nginx no ubuntu server

Nesse artigo vou mostrar como criar um proxy reverso no ngnix do ubuntu server ou debian.

 

Vamos editar o virtualhost , mude de acordo com seu ambiente:

sudo vi /etc/nginx/sites-available/it-howto.org    
server {
    listen  80;

    server_name it-howto.org;
    access_log /var/log/nginx/it-howto.org.access.log;
    error_log /var/log/nginx/it-howto.org.vhost.error.log;


    # proxy reverso
    location / {
    proxy_pass https://35.168.251.244;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
            }
    }



### https 443 # Certificado válido Lets encrypt 


server {
    listen 443 ssl;

    ssl on;
    ssl_certificate /etc/ssl/it-howto.org.pem;
    ssl_certificate_key /etc/ssl/it-howto.org.key;

    server_name it-howto.org;
    access_log /var/log/nginx/it-howto.org.access.ssl.log;
    error_log /var/log/nginx/it-howto.org.vhost.ssl.error.log;

    # proxy reverso
    location / {
    proxy_pass https://35.168.251.244;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

 

Efetuar o teste:

sudo nginx -t
[sudo] password for julio: 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

Criar o link simbólico do virtualhost:

sudo ln -s /etc/nginx/sites-available/it-howto.org /etc/nginx/sites-enabled

Reinciar o serviço:

sudo systemctl restart nginx

Log do servidor:

tail -f /var/log/nginx/*
==> /var/log/nginx/it-howto.org_ssl_error.lg <==
2021/01/27 16:13:43 [error] 7058#7058: *10 open() "/var/www/it-howto.org/html/favicon.ico" failed (2: No such file or directory), client: 10.100.0.2, server: www.it-howto.org, request: "GET /favicon.ico HTTP/2.0", host: "it-howto.org", referrer: "https://it-howto.org/auth/"
2021/01/27 17:45:29 [error] 7349#7349: *9 open() "/var/www/it-howto.org/html/favicon.ico" failed (2: No such file or directory), client: 10.100.0.2, server: it-howto.org, request: "GET /favicon.ico HTTP/1.1", host: "it-howto.org", referrer: "https://it-howto.org/"

==> /var/log/nginx/it-howto.org.vhost.error.log <==
2021/01/27 18:22:53 [error] 7410#7410: *1 open() "/var/www/it-howto.org/html/favicon.ico" failed (2: No such file or directory), client: 10.100.0.2, server: your_very_own_domain.com, request: "GET /favicon.ico HTTP/1.1", host: "it-howto.org", referrer: "https://it-howto.org/"

==> /var/log/nginx/it-howto.org.vhost.ssl.error.log <==

==> /var/log/nginx/it-howto.org.access.ssl.log <==
10.100.0.2 - - [27/Jan/2021:19:15:33 +0000] "POST /wp-admin/post.php HTTP/1.1" 302 0 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:33 +0000] "GET /?p=482&preview=true HTTP/1.1" 200 10202 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-includes/css/admin-bar.min.css?ver=5.6 HTTP/1.1" 200 3667 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-content/plugins/quick-adsense-reloaded/includes/gutenberg/dist/blocks.style.build.css?ver=2.0.19 HTTP/1.1" 200 155 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-content/plugins/google-analytics-for-wordpress/assets/css/frontend.min.css?ver=7.15.0 HTTP/1.1" 200 832 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-content/plugins/quick-adsense-reloaded/assets/js/ads.js HTTP/1.1" 200 66 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-content/plugins/quick-adsense-reloaded/assets/js/ads.js?ver=2.0.19 HTTP/1.1" 200 66 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:34 +0000] "GET /wp-includes/js/comment-reply.min.js?ver=5.6 HTTP/1.1" 200 1362 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:15:38 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 2921 "https://it-howto.org/?p=482&preview=true" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:16:00 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 47 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:17:01 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 123 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:18:00 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 47 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
10.100.0.2 - - [27/Jan/2021:19:19:01 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 123 "https://it-howto.org/wp-admin/post-new.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
^C

 

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *