From b2e4224b2db8e4c7a322555c9be996dea850854a Mon Sep 17 00:00:00 2001 From: Ravachol Date: Wed, 3 Apr 2024 03:18:45 +0800 Subject: [PATCH] fixed nginx configuration --- README.md | 14 +++++++++++++- example.com.conf | 34 ++++++++++++++++++++++++++++++++++ nginx.conf | 37 ++++--------------------------------- 3 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 example.com.conf diff --git a/README.md b/README.md index 2135a20..1b5d94d 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,22 @@ Static resources are hosted in `public/` and the bot-generated contents are unde ``` copy and change the config file to configure Nginx: ``` shell -cp nginx.conf /etc/nginx/sites-available/example.com +cp example.conf /etc/nginx/sites-available/example.com # don't forget to change it !! ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled ``` +add `map` block in `nginx.conf` into your system `nginx.conf`'s `http` block + +``` nginx +http { + # other stuff ... + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; + } +} +``` + restart `nginx.service` ### Running In the project directory, run `python3` diff --git a/example.com.conf b/example.com.conf new file mode 100644 index 0000000..c6cd800 --- /dev/null +++ b/example.com.conf @@ -0,0 +1,34 @@ +# Nginx config template +# Don't forget to change it to meet your own env +upstream uvicorn { + server unix:/tmp/randomology/uvicorn.sock; +} + +server { + listen 80; + listen 443 ssl; + listen [::]:443 ssl; + + client_max_body_size 4G; + + server_name example.com; + + ssl_certificate /path/to/fullchain.pem; + ssl_certificate_key /path/to/privkey.pem; + + location / { + root /var/www/example.com/public; + } + + # your webhook + location /your-webhook-uri { + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_redirect off; + proxy_buffering off; + proxy_pass http://uvicorn/your-webhook-uri; + } +} diff --git a/nginx.conf b/nginx.conf index ddbd765..79946b7 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,37 +1,8 @@ # Nginx config template -# Don't forget to change it to meet your own env +# move map block to system nginx.conf http { - - upstream uvicorn { - server unix:/tmp/randomology/uvicorn.sock; - } - - server { - listen 80; - listen 443 ssl; - listen [::]:443 ssl; - - client_max_body_size 4G; - - server_name example.com; - - ssl_certificate /path/to/fullchain.pem; - ssl_certificate_key /path/to/privkey.pem; - - location / { - root /var/www/example.com/public; - } - - # your webhook - location /your-webhook-uri { - proxy_set_header Host $http_host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_redirect off; - proxy_buffering off; - proxy_pass http://uvicorn/randomology; - } + map $http_upgrade $connection_upgrade { + default upgrade; + '' close; } }