summaryrefslogtreecommitdiffhomepage
path: root/nginx/sites-available/vps
blob: 2a932125d27cd0ed030e76da3db3a6044918586f (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#map $token $api_client_name {
#    default "";
#
#    # CAUTION!! Change token and client name wisely
#    "XXXX" "client";
#}

# Gets the basename of the original request
map $request_uri $request_basename {
  ~/(?<captured_request_basename>[^/?]*)(?:\?|$) $captured_request_basename;
}

# Gets the basename of the current uri
map $uri $basename {
  ~/(?<captured_basename>[^/]*)$ $captured_basename;
}

# charset
charset utf-8;
charset_types *;
override_charset on;

server {
  server_name topo.tw www.topo.tw;

  listen 80;
  listen 443 ssl;
  ssl_certificate /home/pham/.acme.sh/topo.tw_ecc/fullchain.cer;
  ssl_certificate_key /home/pham/.acme.sh/topo.tw_ecc/topo.tw.key;
  location .well-known/ {
    root /home/pham/Downloads/.well-known;
  }

  # files
  root /srv/http;
  index index.html;
  #autoindex on;
  #autoindex_exact_size off;
  disable_symlinks off;


  include /etc/nginx/sites-available/topo.tw.tmp;

  include /home/pham/site/nginx/modules/fancyindex/fancyindex.conf;
  location ^~ /fancyindex/ {
    root /home/pham/site/nginx/modules; 
  }

  # header
  proxy_set_header Host $host;
  add_header Cache-Control "no-cache" always;
  #add_header Cache-Control "max-age=604800";
  error_page 404 /404.html;
  error_log /var/log/nginx/error.log debug;
  #rewrite_log on;

  try_files $uri $uri"index.html" $uri/index.html @rewrite_no_slash;

  location @rewrite_no_slash {
    add_header rewrite no_slash;
    rewrite ^(.+)$ $1.html permanent;
  }

  location ~ \.html$ {
    try_files $uri =404;
  }

  # RSS Feed for various names
  # ref: https://blog.jim-nielsen.com/2021/feed-urls/
  location ~ ^/(rss|index.xml|atom|atom.xml|feed|feed.rss|feed.xml|feed.atom)$ {
    alias /srv/http/feed.rss;
    add_header Content-Type "text/xml; charset=utf-8";
  }

  location ~ \.js$ {
    add_header Access-Control-Allow-Origin *;
  }

  rewrite ^/cgi$ /cgi/ permanent;
  location = /cgi/ {
    alias /srv/cgi/;
    fancyindex_ignore Makefile fastcgi.*;
  }

  location ^~ /cgi/ {
    gzip off;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/run/fcgiwrap.sock;
    fastcgi_param SCRIPT_FILENAME /srv/cgi/$basename;
    error_log /tmp/cgi info;
  }

  location ^~ /links/rss/ {
    alias /srv/rss/;
  }

  #location ~ /$ {
  #  try_files $uri @rewrite_slash;
  #}

  #location @rewrite_slash {
  #  rewrite ^(.+)/$ $1.html permanent;
  #}

  rewrite ^/posts$ /posts/ permanent;
  location = /posts/ {
  }

  # This configuration allow you to upload/modify/delete file, for example:
  #   curl -X PUT -F file=@foo https://topo.tw/doc/bar
  location ^~ /doc {
    alias /home/pham/doc/;

    client_body_temp_path /tmp/client_temp;
    dav_methods PUT DELETE MKCOL COPY MOVE;
    create_full_put_path  on;
    dav_access            group:rw  all:r;
    client_max_body_size 10000m;
  }

  location ^~ /photos/ {
    alias /home/pham/data/s3.photos/;
    #autoindex_format xml;
    #xslt_string_param title "photos";
    #xslt_stylesheet layout/gal.xslt;
    try_files $uri $uri/ =404;
    expires max;

    if ($uri ~ ^/photos/([^!]+)!(large|lg|md)$ ) {
      set $filename /home/pham/data/s3.photos/$1;
      set $img_version $2;
      rewrite ^ /thumbnail;
    }
  }

  rewrite ^/p(ublic)?$ /public/ permanent;
  rewrite ^/p/(.*)$ /public/$1;
  location ^~ /public/ {
    alias /home/pham/public/;
    autoindex_format xml;
    xslt_string_param title "/posts/";
    xslt_stylesheet layout/simple.xslt;
    add_header Access-Control-Allow-Origin "*" always;
    add_header Cache-Control "no-cache" always;
  }

  # thumbnail CGI, requires variables 'filename' and 'img_version'
  location = /thumbnail {
    # Prepare the required parameters (width, height, cropping or zooming) according to the URL address!
    set $img_type resize;
    set $img_w    -;
    set $img_h    -;
    if ($img_version = 'large') {
      set $img_type resize;
      set $img_w    1920;
    }
    if ($img_version = 'lg') {
      set $img_type crop;
      set $img_w    256;
      set $img_h    256;
    }
    if ($img_version = 'md') {
      set $img_type crop;
      set $img_w    128;
      set $img_h    128;
    }
    rewrite ^ /_$img_type;
  }

  # Processing of Scaled Pictures
  location = /_resize {
    alias $filename;
    image_filter resize $img_w $img_h;
    image_filter_jpeg_quality 95;
    image_filter_buffer         20M;
    image_filter_interlace      on;
  }

  # Processing of clipped pictures
  location = /_crop {
    alias $filename;
    image_filter crop $img_w $img_h;
    image_filter_jpeg_quality 95;
    image_filter_buffer         20M;
    image_filter_interlace      on;
  }

  location ^~ /wallpapers {
    alias /home/pham/public/wallpapers/;

    autoindex on;
    autoindex_format xml;
    xslt_string_param title "Wallpaper Collection!";
    xslt_stylesheet layout/gal.xslt;
    try_files $uri $uri/ =404;

    if ($uri ~ ([^/!]+)!(large|lg|md)$ ) {
      set $filename /home/pham/public/wallpapers/$1;
      set $img_version $2;
      rewrite ^ /thumbnail;
    }
  }

  location ^~ /tmp {
    alias /home/pham/public/tmp/;
    autoindex on;
    add_header "Content-Type" "text/plain; charset=utf-8";
  }

  location ^~ /osm {
    #alias /home/pham/public/osm/;
    alias /srv/osm/dist/;
    autoindex on;
  }

  location ^~ /tainan/ {
    alias /home/pham/public/tainan/;
    autoindex on;
    index =404;
  }

  location ^~ /private/ {
    alias /home/pham/private/;
    autoindex on;
    auth_basic "You need to login";
    auth_basic_user_file /etc/nginx/passwd/japan;
  }

  location = /japan.html {
    autoindex on;

    auth_basic "You need to login";
    auth_basic_user_file /etc/nginx/passwd/japan;
  }

  location ^~ /houshou {
    alias /home/pham/data/houshou/;

    autoindex on;
    autoindex_format xml;
    xslt_string_param title "Houshou Collection!";
    xslt_stylesheet layout/gal.xslt;
    try_files $uri $uri/ =404;

    auth_basic "You need to login";
    auth_basic_user_file /etc/nginx/passwd/houshou;

    if ($uri ~ ([^/!]+)!(large|lg|md)$ ) {
      set $filename /home/pham/data/houshou/$1;
      set $img_version $2;
      rewrite ^ /thumbnail;
    }
  }

  location ^~ /houshou2 {
    alias /home/pham/data/houshou2/;

    autoindex on;
    autoindex_format xml;
    xslt_string_param title "Houshou Collection!";
    #xslt_stylesheet layout/simple-gal.xslt;
    xslt_stylesheet layout/gal.xslt;
    try_files $uri $uri/ =404;

    if ($uri ~ ([^/!]+)!(large|lg|md)$ ) {
      set $filename /home/pham/data/houshou2/$1;
      set $img_version $2;
      rewrite ^ /thumbnail;
    }
  }

  location /rescue {
    root /home/pham;

    auth_basic "You need to login";
    auth_basic_user_file /etc/nginx/passwd/rescue;
  }

#  location /upload/ {
#    proxy_pass http://127.0.0.1:8000/;
#  }

  #rewrite ^/up$ /up/;
  #location /up/ {
    #    proxy_set_header X-Forwarded-Proto https;
    #    proxy_set_header Referer $host/up/;
    #    proxy_pass http://127.0.0.1:8080/;

    #    client_max_body_size 1g;
    #}

  #location = /_validate_token {
    #    internal;

    #    if ($token = "") {
      #        return 401; # Unauthorized
      #    }

    #    if ($api_client_name = "") {
      #        return 403; # Forbidden
      #    }

    #    return 204; # OK (no content)
    #}
}

# services for OSM
server {
  server_name osm.topo.tw;
  listen 80;
  listen 443 ssl;
  ssl_certificate /home/pham/.acme.sh/osm.topo.tw_ecc/fullchain.cer;
  ssl_certificate_key /home/pham/.acme.sh/osm.topo.tw_ecc/osm.topo.tw.key;
  root /srv/osm;
}

server {
  server_name rb.topo.tw riverbien.topo.tw;
  listen 80;
  listen 443 ssl;
  ssl_certificate /home/pham/.acme.sh/riverbien.topo.tw_ecc/fullchain.cer;
  ssl_certificate_key /home/pham/.acme.sh/riverbien.topo.tw_ecc/riverbien.topo.tw.key;

  root /srv/riverbien;

  include /home/pham/site/nginx/modules/fancyindex/fancyindex.conf;
  fancyindex_default_sort date_desc;
  location ^~ /fancyindex/ {
    root /home/pham/site/nginx/modules; 
  }
  fancyindex_ignore dist plugin .*png .*jpg;

  add_header Cache-Control "no-cache" always;
}

# git server
server {
  server_name git.topo.tw;

  listen 80;
  listen 443 ssl;
  ssl_certificate /etc/nginx/ssl/git.topo.tw/fullchain.cer;
  ssl_certificate_key /etc/nginx/ssl/git.topo.tw/git.topo.tw.key;

  root /usr/share/webapps/cgit;
  try_files $uri @cgit;

  location @cgit {
    include             fastcgi_params;
    fastcgi_param       SCRIPT_FILENAME /usr/local/lib/cgit/cgit.cgi;
    fastcgi_param       PATH_INFO       $uri;
    fastcgi_param       QUERY_STRING    $args;
    fastcgi_param       HTTP_HOST       $server_name;
    fastcgi_pass        unix:/run/fcgiwrap.sock;
  }

  location = /favicon.ico {
    alias /srv/http/favicon.ico;
  }

  location = /logo.svg {
    alias /home/pham/site/git/assets/logo.svg;
  }

  # Configure HTTP transport
  #location ~ /.+/(info/refs|git-upload-pack) {
  #  include             fastcgi_params;
  #  fastcgi_param       SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
  #  fastcgi_param       PATH_INFO           $uri;
  #  fastcgi_param       GIT_HTTP_EXPORT_ALL 1;
  #  fastcgi_param       GIT_PROJECT_ROOT    /srv/git;
  #  fastcgi_param       HOME                /srv/git;
  #  fastcgi_pass        unix:/run/fcgiwrap.sock;
  #}

}

#server {
#  server_name rb.topo.tw riverbien.topo.tw;
#  root /home/pham/Downloads;
#  listen 80;
#}

# TODO, WORKING
#server {
#  server_name feed.topo.tw;
#  listen 443 ssl;
#  ssl_certificate /home/pham/.acme.sh/feed.topo.tw_ecc/feed.topo.tw.cer;
#  ssl_certificate_key /home/pham/.acme.sh/feed.topo.tw_ecc/feed.topo.tw.key;
#
#  location / {
#    alias /srv/http/feed.rss;
#  }
#}

# Block all direct accesses via IP address
#server {
#  server_name "~[\d\.]+";
#  listen 80;
#  error_page 404 /404.html;
#  return 404;
#}

## Redirect 80 to 443
#server {
#  if ($host = topo.tw) {
#    return 301 https://$host$request_uri;
#  } # managed by Certbot
#
#
#  #listen 80;
#  server_name topo.tw;
#  return 301 https://$host$request_uri;
#
#
#}

## Forward Proxy
#server {
#  resolver 8.8.8.8;
#  listen 13288;
#
#  proxy_connect;
#  proxy_connect_allow            443 563;
#  proxy_connect_connect_timeout  10s;
#  proxy_connect_read_timeout     10s;
#  proxy_connect_send_timeout     10s;
#  location / {
#    proxy_pass http://$host;
#    proxy_set_header Host $host;
#  }
#}

#server {
#  server_name demo.topo.tw;
#  root /;
#
#  location / {
#    index /home/pham/git/vps/demo/client.sh;
#    add_header Content-Type text/plain;
#  }
#  #listen 80;
#}