Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

238 Zeilen
6.1 KiB

  1. {%- macro nginx_map(from_variable, to_variable, values, default) %}
  2. map {{ from_variable }} {{ to_variable }} {
  3. {% for (from, to) in values.items() -%}
  4. {{ from }} {{ to }};
  5. {% endfor %}
  6. {%- if default -%}
  7. default {{ default }};
  8. {% endif %}
  9. }
  10. {%- endmacro %}
  11. {%- macro server_block(bench_name, port, server_names, site_name, sites_path, ssl_certificate, ssl_certificate_key) %}
  12. server {
  13. {% if ssl_certificate and ssl_certificate_key %}
  14. listen {{ port }} ssl;
  15. listen [::]:{{ port }} ssl;
  16. {% else %}
  17. listen {{ port }};
  18. listen [::]:{{ port }};
  19. {% endif %}
  20. server_name
  21. {% for name in server_names -%}
  22. {{ name }}
  23. {% endfor -%}
  24. ;
  25. root {{ sites_path }};
  26. {% if allow_rate_limiting %}
  27. limit_conn per_host_{{ bench_name_hash }} 8;
  28. {% endif %}
  29. proxy_buffer_size 128k;
  30. proxy_buffers 4 256k;
  31. proxy_busy_buffers_size 256k;
  32. {% if ssl_certificate and ssl_certificate_key %}
  33. ssl_certificate {{ ssl_certificate }};
  34. ssl_certificate_key {{ ssl_certificate_key }};
  35. ssl_session_timeout 5m;
  36. ssl_session_cache shared:SSL:10m;
  37. ssl_session_tickets off;
  38. ssl_stapling on;
  39. ssl_stapling_verify on;
  40. ssl_protocols TLSv1.2 TLSv1.3;
  41. ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
  42. ssl_ecdh_curve secp384r1;
  43. ssl_prefer_server_ciphers on;
  44. {% endif %}
  45. add_header X-Frame-Options "SAMEORIGIN";
  46. add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
  47. add_header X-Content-Type-Options nosniff;
  48. add_header X-XSS-Protection "1; mode=block";
  49. add_header Referrer-Policy "same-origin, strict-origin-when-cross-origin";
  50. location /assets {
  51. try_files $uri =404;
  52. add_header Cache-Control "max-age=31536000";
  53. }
  54. location ~ ^/protected/(.*) {
  55. internal;
  56. try_files /{{ site_name }}/$1 =404;
  57. }
  58. location /socket.io {
  59. proxy_http_version 1.1;
  60. proxy_set_header Upgrade $http_upgrade;
  61. proxy_set_header Connection "upgrade";
  62. proxy_set_header X-Xhiveframework-Site-Name {{ site_name }};
  63. proxy_set_header Origin $scheme://$http_host;
  64. proxy_set_header Host $host;
  65. proxy_pass http://{{ bench_name }}-socketio-server;
  66. }
  67. location / {
  68. rewrite ^(.+)/$ $1 permanent;
  69. rewrite ^(.+)/index\.html$ $1 permanent;
  70. rewrite ^(.+)\.html$ $1 permanent;
  71. location ~* ^/files/.*.(htm|html|svg|xml) {
  72. add_header Content-disposition "attachment";
  73. try_files /{{ site_name }}/public/$uri @webserver;
  74. }
  75. try_files /{{ site_name }}/public/$uri @webserver;
  76. }
  77. location @webserver {
  78. proxy_http_version 1.1;
  79. proxy_set_header X-Forwarded-For $remote_addr;
  80. proxy_set_header X-Forwarded-Proto $scheme;
  81. proxy_set_header X-Xhiveframework-Site-Name {{ site_name }};
  82. proxy_set_header Host $host;
  83. proxy_set_header X-Use-X-Accel-Redirect True;
  84. proxy_read_timeout {{ http_timeout or 120 }};
  85. proxy_redirect off;
  86. proxy_pass http://{{ bench_name }}-xhiveframework;
  87. }
  88. # error pages
  89. {% for error_code, error_page in error_pages.items() -%}
  90. error_page {{ error_code }} /{{ error_page.split('/')[-1] }};
  91. location /{{ error_code }}.html {
  92. root {{ '/'.join(error_page.split('/')[:-1]) }};
  93. internal;
  94. }
  95. {% endfor -%}
  96. {% if logging %}
  97. {%- if logging.level == "site" -%}
  98. access_log /var/log/nginx/{{ site_name }}_access.log {{ logging.log_format }};
  99. error_log /var/log/nginx/{{ site_name }}_error.log;
  100. {%- elif logging.level == "combined" -%}
  101. access_log /var/log/nginx/access.log {{ logging.log_format }};
  102. error_log /var/log/nginx/error.log;
  103. {%- endif %}
  104. {%- endif %}
  105. # optimizations
  106. sendfile on;
  107. keepalive_timeout 15;
  108. client_max_body_size 50m;
  109. client_body_buffer_size 16K;
  110. client_header_buffer_size 1k;
  111. # enable gzip compresion
  112. # based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
  113. gzip on;
  114. gzip_http_version 1.1;
  115. gzip_comp_level 5;
  116. gzip_min_length 256;
  117. gzip_proxied any;
  118. gzip_vary on;
  119. gzip_types
  120. application/atom+xml
  121. application/javascript
  122. application/json
  123. application/rss+xml
  124. application/vnd.ms-fontobject
  125. application/x-font-ttf
  126. application/font-woff
  127. application/x-web-app-manifest+json
  128. application/xhtml+xml
  129. application/xml
  130. font/opentype
  131. image/svg+xml
  132. image/x-icon
  133. text/css
  134. text/plain
  135. text/x-component
  136. ;
  137. # text/html is always compressed by HttpGzipModule
  138. }
  139. {% if ssl_certificate and ssl_certificate_key -%}
  140. # http to https redirect
  141. server {
  142. listen 80;
  143. server_name
  144. {% for name in server_names -%}
  145. {{ name }}
  146. {% endfor -%}
  147. ;
  148. return 301 https://$host$request_uri;
  149. }
  150. {% endif %}
  151. {%- endmacro -%}
  152. upstream {{ bench_name }}-xhiveframework {
  153. server 127.0.0.1:{{ webserver_port or 8000 }} fail_timeout=0;
  154. }
  155. upstream {{ bench_name}}-socketio-server {
  156. server 127.0.0.1:{{ socketio_port or 3000 }} fail_timeout=0;
  157. }
  158. {% if allow_rate_limiting %}
  159. limit_conn_zone $host zone=per_host_{{ bench_name_hash }}:{{ limit_conn_shared_memory }}m;
  160. {% endif %}
  161. # setup maps
  162. {%- set site_name_variable="$host" %}
  163. {% if sites.domain_map -%}
  164. {# we append these variables with a random string as there could be multiple benches #}
  165. {%- set site_name_variable="$site_name_{0}".format(random_string) -%}
  166. {{ nginx_map(from_variable="$host", to_variable=site_name_variable, values=sites.domain_map, default="$host") }}
  167. {%- endif %}
  168. # server blocks
  169. {% if sites.that_use_dns -%}
  170. {{ server_block(bench_name, port=80, server_names=sites.that_use_dns, site_name=site_name_variable, sites_path=sites_path) }}
  171. {%- endif %}
  172. {% if sites.that_use_wildcard_ssl -%}
  173. {{ server_block(bench_name, port=443, server_names=sites.that_use_wildcard_ssl,
  174. site_name=site_name_variable, sites_path=sites_path,
  175. ssl_certificate=sites.wildcard_ssl_certificate,
  176. ssl_certificate_key=sites.wildcard_ssl_certificate_key) }}
  177. {%- endif %}
  178. {%- if sites.that_use_ssl -%}
  179. {% for site in sites.that_use_ssl -%}
  180. {{ server_block(bench_name, port=443, server_names=[site.domain or site.name],
  181. site_name=site_name_variable, sites_path=sites_path,
  182. ssl_certificate=site.ssl_certificate, ssl_certificate_key=site.ssl_certificate_key) }}
  183. {% endfor %}
  184. {%- endif %}
  185. {% if sites.that_use_port -%}
  186. {%- for site in sites.that_use_port -%}
  187. {{ server_block(bench_name, port=site.port, server_names=[site.name], site_name=site.name, sites_path=sites_path) }}
  188. {%- endfor %}
  189. {% endif %}