Caddy Simple Reverse Proxy

2019-12-25 21:48:39

Caddy Simple Reverse Proxy

Reference: https://zixizixi.cn/caddyserver-r-proxy-https

1. Get Caddy

https://github.com/caddyserver/caddy/releases

# Currently 2.0 is still in beta stage, 1.0.4 is the latest stable version
wget https://github.com/caddyserver/caddy/releases/download/v1.0.4/caddy_v1.0.4_linux_amd64.tar.gz

# Install Caddy to local command
tar xf caddy_v1.0.4_linux_amd64.tar.gz
sudo mv caddy / usr / local / bin /

# Clear the redundant files generated by the
compression rm -rf CHANGES.txt LICENSES.txt README.txt init / caddy_v1.0.4_linux_amd64.tar.gz


2. Configure
Caddyfile under the current directory of Caddy.
# Us2.suzhi82.tk The IP of the corresponding server needs to be set on the DNS SERVER first, otherwise the https certificate cannot be applied.
# Use https for the reverse proxy server 127.0.0.1:8000 This service , Default 80 will go to port 443
https://us2.suzhi82.tk {
  gzip 
  proxy / 127.0.0.1:8000/
}

# If you only want to use http for reverse proxy, the default is to only open port 80
http://us2.suzhi82.tk {
  gzip 
  proxy / 127.0.0.1:8000/
}


3. Start Caddy
# caddy will read the Caddyfile in the current directory by default.
Sudo caddy # Email can be left without writing, just press Enter

Solution: WARNING: File descriptor limit 1024 is too low for production servers.
# View system parameter
ulimit -a

# Modify system open files limit, default 1024
ulimit -n 8192

# Start Caddy again and there will be no Warming in production environment.
Sudo caddy


Fourth, the reverse proxy sample demo
# python3.8 + virtualenv + Django2.2.3

# Create a virtual environment and install Django
cd && mkdir venvs && cd venvs
virtualenv testenv
source testenv / bin / activate
pip install django == 2.2.3

# Create a Django project and start
django-admin startproject testproj
cd testproj
python manage.py runserver

# At this point, a 127.0.0.1:8000 service that only the server itself can access is started

# Create a new terminal and use the Caddy reverse proxy service to the public network
cd && cat> Caddyfile << EOF
https://us1.suzhi82.tk {
  gzip 
  proxy / 127.0.0.1:8000/
}
EOF

ulimit -n 8192 # See above, just execute it once
sudo caddy # Email can be written, just enter


------------------------------------------------------
Finish!

Published 27 original articles · praised 4 · visits 9693

Guess you like

Origin blog.csdn.net/yoshubom/article/details/103705078