nginx.conf 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # keep in sync with server-ce/nginx/clsi-nginx.conf
  2. server {
  3. add_header 'X-Served-By' 'clsi-nginx' always;
  4. listen 8080;
  5. server_name clsi-nginx;
  6. server_tokens off;
  7. access_log off;
  8. # Ignore symlinks possibly created by users
  9. disable_symlinks on;
  10. # enable compression for tex auxiliary files, but not for pdf files
  11. gzip on;
  12. gzip_types text/plain;
  13. gzip_proxied any;
  14. types {
  15. text/plain log blg aux stdout stderr;
  16. application/pdf pdf;
  17. }
  18. # user content domain access check
  19. # The project-id is zero prefixed. No actual user project uses these ids.
  20. # mongo-id 000000000000000000000000 -> 1970-01-01T00:00:00.000Z
  21. # mongo-id 000000010000000000000000 -> 1970-01-01T00:00:01.000Z
  22. # mongo-id 100000000000000000000000 -> 1978-07-04T21:24:16.000Z
  23. # This allows us to distinguish between check-traffic and regular output traffic.
  24. location ~ ^/project/0([0-9a-f]+)/user/([0-9a-f]+)/build/([0-9a-f-]+)/output/output\.pdf$ {
  25. if ($request_method = 'OPTIONS') {
  26. # handle OPTIONS method for CORS requests
  27. add_header 'Allow' 'GET,HEAD';
  28. return 204;
  29. }
  30. alias /var/clsi/tiny.pdf;
  31. }
  32. location ~ ^/project/0([0-9a-f]+)/build/([0-9a-f-]+)/output/output\.pdf$ {
  33. if ($request_method = 'OPTIONS') {
  34. # handle OPTIONS method for CORS requests
  35. add_header 'Allow' 'GET,HEAD';
  36. return 204;
  37. }
  38. alias /var/clsi/tiny.pdf;
  39. }
  40. # handle output files for specific users
  41. location ~ ^/project/([0-9a-f]+)/user/([0-9a-f]+)/build/([0-9a-f-]+)/output/(.+)$ {
  42. if ($request_method = 'OPTIONS') {
  43. # handle OPTIONS method for CORS requests
  44. add_header 'Allow' 'GET,HEAD';
  45. return 204;
  46. }
  47. rewrite ^/project/([0-9a-f]+)/user/([0-9a-f]+)/build/([0-9a-f-]+)/output/(.+)$ /$4 break;
  48. root /output/$1-$2/generated-files/$3/;
  49. }
  50. # handle output files for anonymous users
  51. location ~ ^/project/([0-9a-f]+)/build/([0-9a-f-]+)/output/(.+)$ {
  52. if ($request_method = 'OPTIONS') {
  53. # handle OPTIONS method for CORS requests
  54. add_header 'Allow' 'GET,HEAD';
  55. return 204;
  56. }
  57. rewrite ^/project/([0-9a-f]+)/build/([0-9a-f-]+)/output/(.+)$ /$3 break;
  58. root /output/$1/generated-files/$2/;
  59. }
  60. # handle output files for submissions
  61. location ~ ^/project/([a-zA-Z0-9_-]+)/build/([0-9a-f-]+)/output/(.+)$ {
  62. if ($request_method = 'OPTIONS') {
  63. # handle OPTIONS method for CORS requests
  64. add_header 'Allow' 'GET,HEAD';
  65. return 204;
  66. }
  67. rewrite ^/project/([a-zA-Z0-9_-]+)/build/([0-9a-f-]+)/output/(.+)$ /$3 break;
  68. root /output/$1/generated-files/$2/;
  69. }
  70. # PDF range for specific users
  71. location ~ ^/project/([0-9a-f]+)/user/([0-9a-f]+)/content/([0-9a-f-]+/[0-9a-f]+)$ {
  72. if ($request_method = 'OPTIONS') {
  73. # handle OPTIONS method for CORS requests
  74. add_header 'Allow' 'GET,HEAD';
  75. return 204;
  76. }
  77. # Cache for one day
  78. expires 1d;
  79. alias /output/$1-$2/content/$3;
  80. }
  81. # PDF range for anonymous users
  82. location ~ ^/project/([0-9a-f]+)/content/([0-9a-f-]+/[0-9a-f]+)$ {
  83. if ($request_method = 'OPTIONS') {
  84. # handle OPTIONS method for CORS requests
  85. add_header 'Allow' 'GET,HEAD';
  86. return 204;
  87. }
  88. # Cache for one day
  89. expires 1d;
  90. alias /output/$1/content/$2;
  91. }
  92. # status endpoint for haproxy httpchk option
  93. location /status {
  94. return 200;
  95. }
  96. # load shedding probe
  97. location = /instance-state {
  98. alias /var/clsi/instance-state;
  99. }
  100. # Do not look up any non matching files in the default root.
  101. location / {
  102. return 404;
  103. }
  104. }