Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Created February 20, 2024 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/b65c33000eb04dbd2ba4d04fe9b48cbf to your computer and use it in GitHub Desktop.
Save jrichardsz/b65c33000eb04dbd2ba4d04fe9b48cbf to your computer and use it in GitHub Desktop.
nginx snippets
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include "conf.d/*.conf";
}

conf.d shoud contain a valida *.conf files.

vim /etc/nginx/conf.d/sysmon.conf 
server {
    listen 80;
    server_name sysmon.tecmint.lan;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://192.168.43.31:5000;
    }
}

complex web

server {
    listen       80;
    server_name  horus.org;

    location ~ ^/horus-web/(.*)$ {
      proxy_pass http://localhost:3150/$1$is_args$args;
    }

}

create self signed cert

req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

config

server {
    listen 80;
    server_name foo.acme.com;

    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://10.10.20.30:8081;
    }
}

server {
    listen 443 ssl;
	server_name foo.acme.com;
	
    ssl_certificate "C:\Users\foo\Desktop\certificate.crt";
    ssl_certificate_key "C:\Users\foo\Desktop\privateKey.key";
	  
    location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://10.10.20.30:8081;
    }	  
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment