Skip to content

doiftrue/local-revers-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Local Reverse Proxy

A simple proxy server for local development that allows using the basic ports 80 and 443, which will be proxied to other ports depending on the specified domain.

For example, when navigating to the URL https://my-site.loc, the request will be forwarded (proxied) to https://localhost:44310, where another web server, such as one running in a Docker container, is operating.

Thanks to this approach, we can run many local web servers (e.g., Nginx) on different ports and work with all sites simultaneously, as if they are all running on port 80 or 443.

SSL note: "Local Reverse Proxy" is not responsible for setting up and verifying SSL certificates—it simply proxies everything to the specified port. Certificates should be located and installed on the proxied servers.

Installation

  • Run cp config/sites.conf.sample config/sites.conf - copy "sites.conf.sample" to "sites.conf".
  • Set up your sites in sites.conf.
  • Run make d.up.
  • Go to any of your sites.

NOTE: Ensure that you add your local domains to the system hosts file.

How to set up a site in "sites.conf"

There are two configuration options for different ports: 80 (http) and 443 (https).

It's very simple:

  • Open the config/sites.conf file.
  • If your site works only over http, add it to the http block.
  • If your site works only over https, add it to the https block.
  • If it works on both schemes (e.g., redirects from http to https), add it to both blocks. This might be necessary to check how the redirect works.

Something Useful

Nginx

Connect to the container:

make nginx.connect
# OR
docker exec -it REVERSE_PROXY_nginx sh

Helpful commands inside the container:

nginx -t         # Test config
nginx -T         # Test & Dump config
nginx -s reload  # Reload the config file without stopping the server
nginx -s quit    # Stop the Nginx server gracefully (allowing active connections to complete)
nginx -s stop    # Stop the Nginx server
nginx -V         # Version and configure options
nginx -V 2>&1 | tr ' ' '\n' | grep -- '--with-' # Modules
ls -al /usr/lib/nginx/modules                   # Additional modules by --modules-path=/usr/lib/nginx/modules

Useful links

Nginx all directives: https://nginx.org/ru/docs/dirindex.html

Nginx as a Reverse Stream Proxy: https://www.eigenmagic.com/2021/09/20/nginx-as-a-reverse-stream-proxy/

Detect HTTP headers for stream

Nginx variables examples

$protocol=TCP
$status=200
$hostname=ubuntu
$server_name=
$ssl_preread_server_name=-          (http)
$ssl_preread_server_name=holder.loc (https)
$server_addr=127.0.0.2
$remote_addr=127.0.0.1
$upstream_addr=127.0.0.1:8019

About

Simple proxy server for local development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published