First Let we see how to use the NGINX, download the NGINX from the online. then unzip the folder in the C: drive. now go inside the nginx folder, and open the conf folder, inside you may find the nginx.conf file. open it.
you will see two things namely
server name is the localhost which is listen in 80 port, that means when ever any one browse http://localhost:80, nginx will get executed or process the request.
If you see above configuration you can notice that after location / or /react are the path, for which it routes to backend server map at proxy_pass directive.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate.crtThen configure the SSL, paste the two files crt and private key in a folder inside nginx folder and refer it in conf file.
ssl_certificate ../cert/certificate.crt; ssl_certificate_key ../cert/private.key;
upstream backend-servers { server localhost:4200 weight=1; server localhost:4201 weight=1; } server { listen 443 ssl; server_name localhost; ssl_certificate ../cert/certificate.crt; ssl_certificate_key ../cert/private.key; location / { proxy_pass http://backend-servers; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /react { proxy_pass http://localhost:4202/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
Example of Config section for Http
upstream backend-servers { server localhost:4200 weight=1; server localhost:4201 weight=1; } server { listen 80; server_name localhost; location / { proxy_pass http://backend-servers; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /react { proxy_pass http://localhost:4202/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
From this article you may find the some basics of NGINX.
No comments:
Post a Comment