Skip to content

Commit 7ef5434

Browse files
committed
add nginx conf
1 parent 0d3fa46 commit 7ef5434

File tree

3 files changed

+87
-15
lines changed

3 files changed

+87
-15
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pip3 install -r requirements.txt
2020
./run.sh run
2121
```
2222

23-
- __then run onl-frontent
23+
- __then run onl-frontent__
2424

2525
for more details check [OpenNetLab-FE](onl-fe)
26+
27+
- run nginx using local configuration
28+
29+
```
30+
sudo nginx -c <absolute-dir-path>/nginx.conf
31+
```

run.sh renamed to manage

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#! /bin/bash
22

3-
[[ $# -ne 1 ]] && exit
3+
function print_help {
4+
echo "usage:"
5+
echo " ./manage [makemigrations|migrate|clean|rebuild|run]"
6+
}
7+
8+
[[ $# -ne 1 ]] && print_help && exit
49

510
cmd=$1
611
apps=("account" "announcement" "conf" "contest" "options" "problem" "submission")
@@ -22,21 +27,11 @@ function migrate {
2227
python3 manage.py inituser --username=root --password=rootroot --action=create_super_admin
2328
}
2429

25-
if [[ $cmd == "make" || $cmd == "makemigrations" ]]; then
26-
for app in "${apps[@]}"; do
27-
python3 manage.py makemigrations $app
28-
done
29-
elif [[ $cmd == "migrate" ]]; then
30-
migrate
31-
elif [[ $cmd == "clean" ]]; then
32-
clean
33-
elif [[ $cmd == "rebuild" ]]; then
34-
clean
35-
migrate
36-
elif [[ $cmd == "run" ]]; then
30+
function run {
3731
# run dramatiq
3832
pgrep dramatiq > /dev/null
39-
33+
34+
# using postgres
4035
# docker run -it -d -e POSTGRES_DB=onlinejudge -e POSTGRES_USER=onlinejudge -e POSTGRES_PASSWORD=onlinejudge -p 5435:5432 --name oj-postgres-dev postgres:10-alpine
4136

4237
if [[ $? -ne 0 ]]; then
@@ -55,4 +50,19 @@ elif [[ $cmd == "run" ]]; then
5550
fi
5651

5752
python3 manage.py runserver 0.0.0.0:7890
53+
}
54+
55+
if [[ $cmd == "make" || $cmd == "makemigrations" ]]; then
56+
for app in "${apps[@]}"; do
57+
python3 manage.py makemigrations $app
58+
done
59+
elif [[ $cmd == "migrate" ]]; then
60+
migrate
61+
elif [[ $cmd == "clean" ]]; then
62+
clean
63+
elif [[ $cmd == "rebuild" ]]; then
64+
clean
65+
migrate
66+
elif [[ $cmd == "run" ]]; then
67+
run
5868
fi

nginx.conf

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# user onl;
2+
3+
# Set number of worker processes automatically based on number of CPU cores.
4+
worker_processes auto;
5+
6+
# Enables the use of JIT for regular expressions to speed-up their processing.
7+
pcre_jit on;
8+
9+
# set pid path
10+
pid /tmp/nginx.pid;
11+
12+
# Includes files with directives to load dynamic modules.
13+
include /etc/nginx/modules/*.conf;
14+
15+
events {
16+
# The maximum number of simultaneous connections that can be opened by
17+
# a worker process.
18+
worker_connections 1024;
19+
}
20+
21+
http {
22+
# Don't tell nginx version to clients.
23+
server_tokens off;
24+
25+
# Specifies the maximum accepted body size of a client request, as
26+
# indicated by the request header Content-Length. If the stated content
27+
# length is greater than this size, then the client receives the HTTP
28+
# error code 413. Set to 0 to disable.
29+
client_max_body_size 5m;
30+
31+
# Timeout for keep-alive connections. Server will close connections after
32+
# this time.
33+
keepalive_timeout 10;
34+
35+
# Enable gzipping of responses.
36+
gzip on;
37+
gzip_types application/javascript text/css;
38+
39+
# Specifies the main log format.
40+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
41+
'$status $body_bytes_sent "$http_referer" '
42+
'"$http_user_agent" "$http_x_forwarded_for"';
43+
44+
server {
45+
listen 80;
46+
# server_name your-domain.com;
47+
48+
location / {
49+
proxy_pass http://127.0.0.1:8080;
50+
proxy_set_header Host $host;
51+
proxy_set_header X-Real-IP $remote_addr;
52+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
53+
proxy_set_header X-Forwarded-Proto $scheme;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)