Skip to content

Instantly share code, notes, and snippets.

@SwadhInz
Forked from edm00se/ReadMe.md
Created January 26, 2021 23:52
Show Gist options
  • Select an option

  • Save SwadhInz/dce94863f735a5455a9221cbdf514e19 to your computer and use it in GitHub Desktop.

Select an option

Save SwadhInz/dce94863f735a5455a9221cbdf514e19 to your computer and use it in GitHub Desktop.
Sample nginx.conf settings to perform reverse proxy functionality to.

Read Me

In order to access a server hosted within a vm, for development purposes, which is restricted to same origin / localhost only requests, I set up a siple nginx reverse proxy to forward my requests.

Steps

  1. To install in a Windows VM, download and install nginx from the current, stable release; I installed to C:\nginx\
  2. Edit the <install path>/conf/nginx.conf file with the marked changes in the file of the same name in this gist.
  3. Start the nginx executable, located in your install path. There are service wrappers for Windows, or you can just kill the process to stop the nginx instance.

Commands for Windows

More information on the implementation of nginx in Windows can be found on the corresponding docs page. Here's the basic breakdown of commands, form within the nginx install directory:

Command
start nginx starts the process
nginx -s stop fast shutdown
nginx -s quit graceful shutdown
nginx -s reload config change, graceful shutdown of existing worker proc, starts new with new config
nginx -s reopen re-open log files

Description

The config file contains a server {} block, inside which is a location / {} block. Inside that location block, we need to comment out the root and index assignment and add in a proxy_pass http://127.0.0.1:8080; line and a proxy_http_version 1.1; line.

Profit

...
server {
listen 80;
server_name localhost;
# adds gzip options
gzip on;
gzip_types text/css text/plain text/xml application/xml application/javascript application/x-javascript text/javascript application/json text/x-json;
gzip_proxied no-store no-cache private expired auth;
#gzip_min_length 1000;
gzip_disable "MSIE [1-6]\.";
...
#location / {
# root html;
# index index.html index.htm;
#}
location / {
# Backend server to forward requests to/from
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
# adds gzip
gzip_static on;
}
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment