Skip to content

Commit

Permalink
fixed nginx configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol-yang committed Apr 2, 2024
1 parent 2962a9a commit b2e4224
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
34 changes: 34 additions & 0 deletions example.com.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}
37 changes: 4 additions & 33 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit b2e4224

Please sign in to comment.