From 52b3281dba24a454d5e172b43da35763cfbae984 Mon Sep 17 00:00:00 2001 From: muppeth Date: Sat, 3 Dec 2022 21:03:52 +0100 Subject: [PATCH 1/4] initial work on movim template --- templates/etc/nginx/sites-available/movim.j2 | 65 ++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 templates/etc/nginx/sites-available/movim.j2 diff --git a/templates/etc/nginx/sites-available/movim.j2 b/templates/etc/nginx/sites-available/movim.j2 new file mode 100644 index 0000000..55ad403 --- /dev/null +++ b/templates/etc/nginx/sites-available/movim.j2 @@ -0,0 +1,65 @@ +fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:100m inactive=60m; +fastcgi_cache_key "$scheme$request_method$host$request_uri"; + +{% extends "core.j2" %} + +{% block root %} + root {{ nginx_www_dir }}{{ item.root }}; + index {{ item.index }}; +{% endblock %} + +{% block location %} +## LOCATIONS + location ~ /\. { + deny all; + } + + location = /favicon.ico { + expires 30d; + access_log off; + log_not_found off; + } + + location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ { + expires 30d; + log_not_found off; + } + + location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { + deny all; + } + + location ~ ^/(config|temp|logs)/ { + deny all; + } + + location ~ \.php$ { + fastcgi_pass {{ item.fastcgi_pass }}; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location /ws/ { + proxy_pass {{ item.upstream_schema }}://{{ item.upstream }}:{{ item.upstream_port }}; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + proxy_redirect off; + } + + location /picture { + include fastcgi_params; + + add_header X-Cache $upstream_cache_status; + fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; + fastcgi_cache nginx_cache; + fastcgi_cache_key $request_method$host$request_uri; + fastcgi_cache_valid any 1h; + } + +{% endblock %} -- 2.30.2 From 8c927251826097b72f1602bd20a4e804f15e2e79 Mon Sep 17 00:00:00 2001 From: meaz Date: Mon, 26 Jun 2023 14:21:03 +0200 Subject: [PATCH 2/4] fix issues + set possibility to deploy as proxy --- templates/etc/nginx/sites-available/movim.j2 | 40 ++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/templates/etc/nginx/sites-available/movim.j2 b/templates/etc/nginx/sites-available/movim.j2 index 55ad403..70e4a12 100644 --- a/templates/etc/nginx/sites-available/movim.j2 +++ b/templates/etc/nginx/sites-available/movim.j2 @@ -1,15 +1,41 @@ fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; +#map $http_upgrade $connection_upgrade { +# default upgrade; +# '' close; +# } + {% extends "core.j2" %} {% block root %} root {{ nginx_www_dir }}{{ item.root }}; - index {{ item.index }}; {% endblock %} + {% block location %} ## LOCATIONS + +{% if item.proxy == 'true' %} + location / { + proxy_pass {{ item.proto }}://{{ item.upstream_name }}:{{ item.listen }}; + proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_redirect off; + } + +{% else %} + location / { + index index.php; + add_header Access-Control-Allow-Origin *; + if (!-e $request_filename) { + rewrite ^/(.*) /index.php?query=$1 last; + } + } +{% endif %} + location ~ /\. { deny all; } @@ -20,10 +46,10 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; log_not_found off; } - location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ { - expires 30d; - log_not_found off; - } + # location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ { + # expires 30d; + # log_not_found off; + # } location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { deny all; @@ -39,9 +65,9 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } - + location /ws/ { - proxy_pass {{ item.upstream_schema }}://{{ item.upstream }}:{{ item.upstream_port }}; + proxy_pass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ item.upstream_port }}; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; -- 2.30.2 From 7688f5e400245db2d91198c0f40a25fd78a1f3a9 Mon Sep 17 00:00:00 2001 From: muppeth Date: Sun, 2 Jul 2023 23:19:43 +0200 Subject: [PATCH 3/4] small update to movim template --- templates/etc/nginx/sites-available/movim.j2 | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/templates/etc/nginx/sites-available/movim.j2 b/templates/etc/nginx/sites-available/movim.j2 index 70e4a12..81489d2 100644 --- a/templates/etc/nginx/sites-available/movim.j2 +++ b/templates/etc/nginx/sites-available/movim.j2 @@ -1,11 +1,8 @@ + +{% if item.pic_cache is defined and item.pic_cache == 'true' %} fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=nginx_cache:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; - -#map $http_upgrade $connection_upgrade { -# default upgrade; -# '' close; -# } - +{% endif %} {% extends "core.j2" %} {% block root %} @@ -46,16 +43,11 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; log_not_found off; } - # location ~* \.(txt|js|css|png|jpe?g|gif|ico|svg)$ { - # expires 30d; - # log_not_found off; - # } - location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { deny all; } - location ~ ^/(config|temp|logs)/ { + location ~ ^/(config|temp|log)/ { deny all; } @@ -66,8 +58,9 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; include fastcgi_params; } +{% if item.ws is defined and item.ws == 'true' %} location /ws/ { - proxy_pass {{ item.upstream_proto }}://{{ item.upstream_name }}:{{ item.upstream_port }}; + proxy_pass {{ item.upstream_schema }}://{{ item.upstream_name }}:{{ item.upstream_port }}; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; @@ -77,7 +70,8 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; proxy_set_header X-Forwarded-Proto https; proxy_redirect off; } - +{% endif %} +{% if item.pic_cache is defined and item.pic_cache == 'true' %} location /picture { include fastcgi_params; @@ -87,5 +81,6 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_key $request_method$host$request_uri; fastcgi_cache_valid any 1h; } +{% endif %} {% endblock %} -- 2.30.2 From 4949f3349f024f861e82b406d83cd79de54e64b3 Mon Sep 17 00:00:00 2001 From: muppeth Date: Wed, 18 Oct 2023 00:25:31 +0200 Subject: [PATCH 4/4] updated movim template --- templates/etc/nginx/sites-available/movim.j2 | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/templates/etc/nginx/sites-available/movim.j2 b/templates/etc/nginx/sites-available/movim.j2 index 81489d2..0680a6f 100644 --- a/templates/etc/nginx/sites-available/movim.j2 +++ b/templates/etc/nginx/sites-available/movim.j2 @@ -7,6 +7,7 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; {% block root %} root {{ nginx_www_dir }}{{ item.root }}; + index index.php; {% endblock %} @@ -25,11 +26,8 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; {% else %} location / { - index index.php; - add_header Access-Control-Allow-Origin *; - if (!-e $request_filename) { - rewrite ^/(.*) /index.php?query=$1 last; - } + set $no_cache 1; + try_files $uri $uri/ /index.php$is_args$args; } {% endif %} @@ -43,10 +41,6 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; log_not_found off; } - location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { - deny all; - } - location ~ ^/(config|temp|log)/ { deny all; } @@ -56,6 +50,12 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; + add_header X-Cache $upstream_cache_status; + fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; + fastcgi_cache nginx_cache; + fastcgi_cache_valid any 7d; + fastcgi_cache_bypass $no_cache; + fastcgi_no_cache $no_cache; } {% if item.ws is defined and item.ws == 'true' %} @@ -73,13 +73,8 @@ fastcgi_cache_key "$scheme$request_method$host$request_uri"; {% endif %} {% if item.pic_cache is defined and item.pic_cache == 'true' %} location /picture { - include fastcgi_params; - - add_header X-Cache $upstream_cache_status; - fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; - fastcgi_cache nginx_cache; - fastcgi_cache_key $request_method$host$request_uri; - fastcgi_cache_valid any 1h; + set $no_cache 0; + try_files $uri $uri/ /index.php$is_args$args; } {% endif %} -- 2.30.2