-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnginx.conf
115 lines (95 loc) · 3.18 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
# Without it you got:
# nginx: [emerg] no "events" section in configuration
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
charset utf-8;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "@http_x_forwarded_for"';
access_log /var/log/nginx.log main;
sendfile on;
keepalive_timeout 65;
# Max size for uploaded files.
# Fix it for upload bigger files
# https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
client_max_body_size 10M;
upstream uvicorn {
server unix:/uvicorn_socket/uvicorn.socket fail_timeout=0;
}
# Just redirection from http to https
# No actions for unsafe protocol
server {
listen 80;
listen [::]:80;
server_name localhost;
return 301 https://$host$request_uri;
}
# Secure part (https)
# All locations are here.
server {
listen 443 ssl http2;
# Additional headers
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# SSL settings (https for debug)
# Actually i have my own certificate that out of VCS
# Look here https://blog.filippo.io/mkcert-valid-https-certificates-for-localhost/
ssl_certificate /srv/www/pmdragon/ssl/localhost+2.pem;
ssl_certificate_key /srv/www/pmdragon/ssl/localhost+2-key.pem;
server_name localhost;
# Handling static files (pass to frontend)
# We use it to let Vue router work correctly.
# https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
location / {
root /srv/www/pmdragon/web;
index index.html;
try_files $uri $uri/ /index.html;
}
# Handling some special paths
# Fop pure API we need only api location (Django Rest Framework)
# admin location is Django admin panel
# schema location is for OpenApi schema (need for swagger)
# swagger is list of methods (need schema to work correctly)
location ~ ^/(api|swagger|admin|schema)/ {
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_redirect off;
proxy_buffering off;
proxy_pass http://uvicorn;
}
# Handling socket connections (Django channels)
# We use the same uvicorn upstream as for main applicaton.
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_pass http://uvicorn;
}
# Handling api based static
# For example Django admin css and images
# Or Django Rest Framework rest view
location /static/ {
autoindex off;
alias /srv/www/pmdragon/staticfiles/;
}
# Handling api based media storage
# For example Django uploads like avatars or attachments for issues.
location /media/ {
autoindex off;
alias /srv/www/pmdragon/media/;
}
# I don't want to log such a useless entries as favicon and robots
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
}
}