Skip to content

Instantly share code, notes, and snippets.

@VuongNQ
Last active September 19, 2024 09:48
Show Gist options
  • Save VuongNQ/741c6eabe925d9678d31c5a3f463c3ff to your computer and use it in GitHub Desktop.
Save VuongNQ/741c6eabe925d9678d31c5a3f463c3ff to your computer and use it in GitHub Desktop.
Virtual host Nginx with SSL (Window config)

Requiment:

Step:

1: copy all file key ssl to drive C like: C:\ssl

2: open file nginx.conf in source nginx had unzip and add code below on property http

server{
    listen 80;
    server_name virtualMV.test;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3000; #chú ý đây: IP ra của npm run dev, mỗi máy mỗi khác
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # location /overview {
        #     proxy_pass http://127.0.0.1:3000$request_uri;
        #     proxy_redirect off;
        # }
    }
}

server{
    listen 443 ssl;
    server_name virtualMV.test;
    ssl_certificate C:\ssl\certificate.pem; #key xao ssl
    ssl_certificate_key C:\ssl\private.key; #key xao ssl

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3000; #chú ý đây: IP ra của npm run dev, mỗi máy mỗi khác
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # location /overview {
        #     proxy_pass http://127.0.0.1:3000$request_uri;
        #     proxy_redirect off;
        # }
    }
}

Note: port config must same with port your app

3: start nginx(run file exe first) or reload with command

start nginx

nginx -s reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment