Virtual Host Forward IP in Nginx


This article is a continuation of the previous post about local dns using pihole, so i forward all my domain and subdomain to my nginx VM at my home, from nginx VM i forwarded all domain using virtualhost to other machine/ip, and it’s working very well.

This is my code at nginx side i put in /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/

server {
    listen 443 ssl;
        server_name pihole.my.home;
        ssl_certificate /etc/ssl/my.home.crt;
        ssl_certificate_key /etc/ssl/my.home.key;

        location / {
        proxy_pass http://192.168.0.30/admin/;
        proxy_set_header Host $http_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;
        proxy_set_header X-Forwarded-Host $http_host;
        access_log /var/log/nginx/pihole.access.log;
        error_log /var/log/nginx/pihole.error.log error;
  
    }
}
~  

Pihole as local dns


Cara merubah file .pfx ke crt dan rsa untuk ssl nginx


Catatan pribadi cara merubah file .pfx (biasanya didapat dari pengelola domain) untuk digunakan di nginx web server begini caranya

openssl pkcs12 -in .file.pfx -clcerts -nokeys -out domain.crt

openssl pkcs12 -in file.pfx -nocerts -nodes -out domain.rsa

Langkah selanjutnya tinggal memasukkan crt dan rsa ke nginx config kalian, biasanya ada di /etc/nginx/sites-available/default

Ubah dibagian ini ya

server { listen 443 ssl; server_name domain.com domain.com; 

ssl_certificate /path/to/your/CRT_file/domain.crt; 

ssl_certificate_key /path/to/your/RSA_file/domain.rsa; 

root /var/www/html/; 

index index.html; 

include /etc/nginx/mime.types; }

Done selesai gampang kan?

Happy Coding …

Salam Ngoprek …

Docker compose nginx


Catatan setup nginx di docker supaya bisa ngeload volume diluar file directorynya docker

Buat docker-compose.yml isikan baris perintah dibawah

version: '2'

services:

nginx:

image: nginx:latest

container_name: production_nginx

volumes:

- /home/onix/sites:/usr/share/nginx/html:z #directory internal:directory docker

ports:

- '8080:80'

Udah gitu aja mudah bukan

Happy Coding ..

Salam ngoprek