vicanso / pingap

A reverse proxy like nginx, built on pingora, simple and efficient.
http://pingap.io/pingap-zh/
Apache License 2.0
254 stars 15 forks source link

How to config reverse proxy for domain? #11

Closed adammakowskidev closed 3 months ago

adammakowskidev commented 3 months ago

Hi @vicanso I am just testing Pingap I am wondering how I can create a proxy for a domain and use cache? Can you provide some example? The documentation is small In nginx I do it this way

proxy_cache_path /var/local/cache/domain_net keys_zone=domain_net:10m inactive=1y;

server {
    listen 443 quic reuseport;
    listen [::]:443 quic reuseport;
    listen 443 ssl;
    listen [::]:443 ssl;
    listen 80;
    http2 on;
    http3 on;
    server_name cdn.domain.com;

    # SSL location
    ssl_certificate /var/local/certificate.pem;
    ssl_certificate_key /var/local/private.key;

    # SSL settings
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_early_data on;
    ssl_session_tickets on;

    # http3/quic settings
    http3_stream_buffer_size 1m;

    # global website headers
    add_header Alt-Svc 'h3=":443"; ma=86400';
    add_header Cache-Status $upstream_cache_status;

    # proxy CDN cache settings
    location / {
        proxy_set_header Early-Data $ssl_early_data;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Access-Control-Allow-Origin *;
        proxy_set_header "Connection" "";
        proxy_cache domain_net;
        proxy_cache_valid any 1d;
        proxy_pass https://domain.net;
    }
}
vicanso commented 3 months ago

@adammakowskidev I will make a guidelines in english. The toml configuration like this. By the way, cache plugin is not stable, it will be changed.

[upstreams.cdn-upstream]
addrs = ["cn.bing.com:443"]
sni = "cn.bing.com"
read_timeout = "10s"
idle_timeout = "2m"
write_timeout = "10s"

[locations.cdn-location]
upstream = "cdn-upstream"
path = "/"
proxy_set_headers = [
    "Host:cn.bing.com",
    "Access-Control-Allow-Origin:*",
]
plugins = ["cdnCache"]

[servers.cdn]
addr = "127.0.0.1:6118"
access_log = "combined"
locations = ["cdn-location"]
threads = 1
tls_cert = """
-----BEGIN CERTIFICATE-----
MIIEljCCAv6gAwIBAgIQeYU....
-----END CERTIFICATE-----"""
tls_key = """
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkq.....
-----END PRIVATE KEY-----"""
enabled_h2 = true

[plugins.cdnCache]
category = "cache"
image
adammakowskidev commented 3 months ago

@vicanso Thank you for your response. I need some time to do some tests. Can the cache currently be configured in any way? Example TTL?

adammakowskidev commented 3 months ago

@vicanso Just testing, everything works fine! I just made it so that Caddy provides SSL, pingap handle proxy website + cache and Caddy serve SSL.

Currently, I don't know if there is an option to automatically receive SSL in Pingap?

vicanso commented 3 months ago

@vicanso Thank you for your response. I need some time to do some tests. Can the cache currently be configured in any way? Example TTL?

Cache ttl is parse from http response header cache-control

adammakowskidev commented 3 months ago

So I have to overwrite this header? Many websites have their static files length set to one year. This is a bit long for the cache. Maybe it would be useful to set the cache age separately?

vicanso commented 3 months ago

Cache-Control: public, max-age=xxx, s-maxage=xxx, the s-maxage will be used as ttl. I'll find a way to set the maximum TTL later.

On Jun 6, 2024, at 10:18 PM, Adam Makowski @.***> wrote:

So I have to overwrite this header? Many websites have their static files length set to one year. This is a bit long for the cache. Maybe it would be useful to set the cache age separately?

— Reply to this email directly, view it on GitHubhttps://github.com/vicanso/pingap/issues/11#issuecomment-2152660156, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AADKYZ5S3VFGEATACOLYTKLZGBVSRAVCNFSM6AAAAABIZAGIICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJSGY3DAMJVGY. You are receiving this because you were mentioned.Message ID: @.***>

vicanso commented 3 months ago

@adammakowskidev Now you can set cache max ttl:

[plugins.commonCache]
category = "cache"
eviction = true
lock = "1s"
max_file_size = "1MB"
max_ttl = "5m"
predictor = true

If ttl get from cache-control > 5 minutes, ttl will be set 5 minutes.

github-actions[bot] commented 3 months ago

This question has been stale for a week. It will be closed in an additional day if not updated.

github-actions[bot] commented 3 months ago

This issue has been closed because it has been stalled with no activity.