Skip to content

Commit d7c8d1e

Browse files
authored
Merge pull request #31 from bybatkhuu/dev
🧑‍💻 Add Nginx configuration templates for dynamic and stat…
2 parents 6879f65 + 7d83279 commit d7c8d1e

10 files changed

+420
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# allow 192.168.0.0/24;
2+
3+
# ## Cloudflare settings:
4+
# include /etc/nginx/conf.d/cloudflare/whitelist.conf;
5+
6+
7+
# server {
8+
# listen 192.168.0.1:80;
9+
10+
# ## Nginx stats (basic auth):
11+
# location = /status {
12+
# auth_basic "Closed site";
13+
# auth_basic_user_file /etc/nginx/ssl/.htpasswd;
14+
15+
# allow 127.0.0.1;
16+
# allow 192.168.0.0/24;
17+
# deny all;
18+
# stub_status;
19+
# }
20+
# }
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
upstream api-server {
2+
server 127.0.0.1:8000;
3+
4+
## Or Load Balancing:
5+
# least_conn;
6+
# hash $binary_remote_addr consistent;
7+
# server 127.0.0.1:8000;
8+
# server 127.0.0.1:8001;
9+
# server 127.0.0.1:8002;
10+
}
11+
12+
13+
## HTTP:
14+
server {
15+
listen 80;
16+
listen [::]:80;
17+
18+
## Logging:
19+
access_log /dev/stdout realip_combined if=$loggable;
20+
access_log /var/log/nginx/access.$map_date_now.log realip_combined if=$loggable;
21+
access_log /var/log/nginx/access.json.$map_date_now.log json_combined if=$loggable;
22+
# access_log /var/log/nginx/access.json.$map_date_now.log cf_json_combined if=$loggable;
23+
24+
## Restrict methods:
25+
if ($request_method ~ ^(TRACE)$) {
26+
return '405';
27+
}
28+
29+
## Security headers:
30+
include /etc/nginx/conf.d/security-headers.conf;
31+
32+
## Additional configs:
33+
include /etc/nginx/conf.d/general.conf;
34+
include /etc/nginx/conf.d/well-known.conf;
35+
36+
## Static files:
37+
root /var/www/web/public;
38+
39+
location / {
40+
try_files $uri $uri.html $uri/ =404;
41+
}
42+
43+
# error_page 404 /404.html;
44+
# location = /404.html {
45+
# internal;
46+
# }
47+
48+
# include /etc/nginx/conf.d/error-pages.conf;
49+
50+
## Sub-path as static files:
51+
# location ^~ /demo {
52+
# alias /var/www/demo/public;
53+
# try_files ${_DOLLAR}uri ${_DOLLAR}uri/ =404;
54+
# }
55+
56+
location ^~ /api {
57+
rewrite ^/api/(.*)$ /$1?$args break;
58+
59+
## Cloudflare headers:
60+
# include /etc/nginx/conf.d/cloudflare/proxy.conf;
61+
62+
## Proxy headers:
63+
include /etc/nginx/conf.d/proxy.conf;
64+
# include /etc/nginx/conf.d/proxy-timeout.conf;
65+
include /etc/nginx/conf.d/api-headers.conf;
66+
67+
proxy_pass http://api-server;
68+
}
69+
70+
# include /etc/nginx/conf.d/status.conf;
71+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
upstream api-server {
2+
server 127.0.0.1:8000;
3+
4+
## Or Load Balancing:
5+
# least_conn;
6+
# hash $binary_remote_addr consistent;
7+
# server 127.0.0.1:8000;
8+
# server 127.0.0.1:8001;
9+
# server 127.0.0.1:8002;
10+
}
11+
12+
13+
## HTTPS:
14+
server {
15+
listen 443 ssl;
16+
listen [::]:443 ssl;
17+
http2 on;
18+
19+
## Logging:
20+
access_log /dev/stdout realip_combined if=$loggable;
21+
access_log /var/log/nginx/access.$map_date_now.log realip_combined if=$loggable;
22+
access_log /var/log/nginx/access.json.$map_date_now.log json_combined if=$loggable;
23+
# access_log /var/log/nginx/access.json.$map_date_now.log cf_json_combined if=$loggable;
24+
25+
## Restrict methods:
26+
if ($request_method ~ ^(TRACE)$) {
27+
return '405';
28+
}
29+
30+
## SSL:
31+
include /etc/nginx/conf.d/ssl.conf;
32+
ssl_certificate /etc/nginx/ssl/self.crt;
33+
ssl_certificate_key /etc/nginx/ssl/self.key;
34+
35+
## Security headers:
36+
include /etc/nginx/conf.d/security-headers.conf;
37+
38+
## Additional configs:
39+
include /etc/nginx/conf.d/general.conf;
40+
include /etc/nginx/conf.d/well-known.conf;
41+
42+
## Static files:
43+
root /var/www/web/public;
44+
45+
location / {
46+
try_files $uri $uri.html $uri/ =404;
47+
}
48+
49+
# error_page 404 /404.html;
50+
# location = /404.html {
51+
# internal;
52+
# }
53+
54+
# include /etc/nginx/conf.d/error-pages.conf;
55+
56+
## Sub-path as static files:
57+
# location ^~ /demo {
58+
# alias /var/www/demo/public;
59+
# try_files ${_DOLLAR}uri ${_DOLLAR}uri/ =404;
60+
# }
61+
62+
location ^~ /api {
63+
rewrite ^/api/(.*)$ /$1?$args break;
64+
65+
## Cloudflare headers:
66+
# include /etc/nginx/conf.d/cloudflare/proxy.conf;
67+
68+
## Proxy headers:
69+
include /etc/nginx/conf.d/proxy.conf;
70+
# include /etc/nginx/conf.d/proxy-timeout.conf;
71+
include /etc/nginx/conf.d/api-headers.conf;
72+
73+
proxy_pass http://api-server;
74+
}
75+
76+
# include /etc/nginx/conf.d/status.conf;
77+
}
78+
79+
## HTTP redirect:
80+
server {
81+
listen 80;
82+
listen [::]:80;
83+
84+
location / {
85+
return 301 https://$host$request_uri;
86+
}
87+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
upstream api-server {
2+
server 127.0.0.1:8000;
3+
4+
## Or Load Balancing:
5+
# least_conn;
6+
# hash $binary_remote_addr consistent;
7+
# server 127.0.0.1:8000;
8+
# server 127.0.0.1:8001;
9+
# server 127.0.0.1:8002;
10+
}
11+
12+
13+
# Main domain as static files (HTTPS):
14+
server {
15+
listen 443 ssl;
16+
listen [::]:443 ssl;
17+
http2 on;
18+
server_name example.com www.example.com;
19+
20+
## Logging:
21+
access_log /dev/stdout realip_combined if=$loggable;
22+
access_log /var/log/nginx/example.com.access.$map_date_now.log realip_combined if=$loggable;
23+
access_log /var/log/nginx/example.com.access.json.$map_date_now.log json_combined if=$loggable;
24+
# access_log /var/log/nginx/example.com.access.json.$map_date_now.log cf_json_combined if=$loggable;
25+
26+
## Restrict methods:
27+
if ($request_method ~ ^(TRACE)$) {
28+
return '405';
29+
}
30+
31+
## SSL:
32+
include /etc/nginx/conf.d/ssl.conf;
33+
ssl_stapling on;
34+
ssl_certificate /etc/nginx/ssl/example.com/cert.pem;
35+
ssl_certificate_key /etc/nginx/ssl/example.com/key.pem;
36+
37+
## Security headers:
38+
add_header Access-Control-Allow-Origin "https://example.com" always;
39+
include /etc/nginx/conf.d/security-headers.conf;
40+
41+
## Additional configs:
42+
include /etc/nginx/conf.d/general.conf;
43+
include /etc/nginx/conf.d/well-known.conf;
44+
45+
## Static files:
46+
root /var/www/example.com/public;
47+
48+
location / {
49+
try_files $uri $uri.html $uri/ =404;
50+
}
51+
52+
# error_page 404 /404.html;
53+
# location = /404.html {
54+
# internal;
55+
# }
56+
57+
include /etc/nginx/conf.d/error-pages.conf;
58+
59+
## Sub-path as static files:
60+
# location ^~ /demo {
61+
# alias /var/www/demo.example.com/public;
62+
# try_files ${_DOLLAR}uri ${_DOLLAR}uri/ =404;
63+
# }
64+
65+
# include /etc/nginx/conf.d/status.conf;
66+
}
67+
68+
## Subdomain as reverse proxy (HTTPS):
69+
server {
70+
listen 443 ssl;
71+
listen [::]:443 ssl;
72+
http2 on;
73+
server_name api.example.com;
74+
75+
## Logging:
76+
access_log /dev/stdout realip_combined;
77+
access_log /var/log/nginx/api.example.com.access.$map_date_now.log realip_combined;
78+
access_log /var/log/nginx/api.example.com.access.json.$map_date_now.log json_combined;
79+
# access_log /var/log/nginx/api.example.com.access.json.$map_date_now.log cf_json_combined if=$loggable;
80+
81+
## Restrict methods:
82+
if ($request_method ~ ^(TRACE)$) {
83+
return '405';
84+
}
85+
86+
## SSL:
87+
include /etc/nginx/conf.d/ssl.conf;
88+
ssl_stapling on;
89+
ssl_certificate /etc/nginx/ssl/example.com/cert.pem;
90+
ssl_certificate_key /etc/nginx/ssl/example.com/key.pem;
91+
92+
## Security headers:
93+
# include /etc/nginx/conf.d/security-headers.conf;
94+
95+
## Cloudflare headers:
96+
# include /etc/nginx/conf.d/cloudflare/proxy.conf;
97+
98+
## Proxy headers:
99+
include /etc/nginx/conf.d/proxy.conf;
100+
# include /etc/nginx/conf.d/proxy-timeout.conf;
101+
include /etc/nginx/conf.d/api-headers.conf;
102+
103+
## Reverse proxy:
104+
location / {
105+
# rewrite ^/api/(.*)$ /$1?$args break;
106+
proxy_pass http://api-server;
107+
}
108+
}
109+
110+
## HTTP redirect:
111+
server {
112+
listen 80;
113+
listen [::]:80;
114+
server_name .example.com;
115+
116+
location / {
117+
return 301 https://$host$request_uri;
118+
}
119+
}

0 commit comments

Comments
 (0)