From 374c63c27f35a5be66dd2029322532003756b741 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 10:25:08 -0500 Subject: [PATCH 1/7] convert wp to native nginx --- roles/wordpress/tasks/install.yml | 6 ++++++ .../templates/wordpress-nginx.conf.j2 | 19 +++++++++++++++++++ vars/default_vars.yml | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 roles/wordpress/templates/wordpress-nginx.conf.j2 diff --git a/roles/wordpress/tasks/install.yml b/roles/wordpress/tasks/install.yml index 239e2ea56..4bf624f49 100644 --- a/roles/wordpress/tasks/install.yml +++ b/roles/wordpress/tasks/install.yml @@ -101,6 +101,12 @@ dest: "/etc/{{ apache_config_dir }}/wordpress.conf" when: apache_enabled +- name: Install {{ nginx_config_dir }}/wordpress-nginx.conf from template, for http://box{{ wp_url }} + template: + src: wordpress-nginx.conf.j2 + dest: "{{ nginx_config_dir }}/wordpress-nginx.conf" + when: nginx_enabled + - name: Add 'wordpress_installed' variable values to {{ iiab_state_file }} lineinfile: dest: "{{ iiab_state_file }}" diff --git a/roles/wordpress/templates/wordpress-nginx.conf.j2 b/roles/wordpress/templates/wordpress-nginx.conf.j2 new file mode 100644 index 000000000..d6f98c185 --- /dev/null +++ b/roles/wordpress/templates/wordpress-nginx.conf.j2 @@ -0,0 +1,19 @@ +location {{ wp_url }} { + #rewrite_log on; + root {{ content_base }}; + + location ~ .*\.php$ { + + include fastcgi_params; + fastcgi_pass php; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + location ~ ^({{ wp_url }})(/.*)/$ { + include fastcgi_params; + fastcgi_pass php; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME {{ wp_abs_path }}/index.php; + } +} diff --git a/vars/default_vars.yml b/vars/default_vars.yml index 72dfb04f5..9ea48c12e 100644 --- a/vars/default_vars.yml +++ b/vars/default_vars.yml @@ -240,7 +240,7 @@ nginx_port: "80" nginx_interface: "0.0.0.0" nginx_install: True nginx_enabled: True - +nginx_config_dir: /etc/nginx/conf.d # See also Apache vars {default_language, language_priority} @ top of this file # From f9adf215406397d1b6bbf8991ac783c2fb7fe2be Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 12:20:04 -0500 Subject: [PATCH 2/7] add mediawiki in native nginx --- roles/mediawiki/defaults/main.yml | 4 +- roles/mediawiki/tasks/enable.yml | 18 +++++++ roles/mediawiki/tasks/install.yml | 22 +++++++- .../templates/mediawiki-nginx.conf.j2 | 54 +++++++++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 roles/mediawiki/templates/mediawiki-nginx.conf.j2 diff --git a/roles/mediawiki/defaults/main.yml b/roles/mediawiki/defaults/main.yml index a2ecb92a3..cf6f155d1 100644 --- a/roles/mediawiki/defaults/main.yml +++ b/roles/mediawiki/defaults/main.yml @@ -25,5 +25,5 @@ mediawiki_site_name: Community Wiki mediawiki_install_path: "{{ content_base }}" # /library mediawiki_abs_path: "{{ mediawiki_install_path }}/mediawiki-{{ mediawiki_version }}" -mediawiki_url: /mediawiki -mediawiki_full_url: "http://{{ iiab_hostname }}.{{ iiab_domain }}{{ mediawiki_url }}" # http://box.lan/mediawiki +mediawiki_url: /wiki +mediawiki_full_url: "http://{{ iiab_hostname }}.{{ iiab_domain }}{{ mediawiki_url }}" # http://box.lan/wiki diff --git a/roles/mediawiki/tasks/enable.yml b/roles/mediawiki/tasks/enable.yml index 4acbe1e12..3b780c43d 100644 --- a/roles/mediawiki/tasks/enable.yml +++ b/roles/mediawiki/tasks/enable.yml @@ -17,6 +17,24 @@ daemon_reload: yes state: restarted +- name: Install {{ nginx_config_dir }}/mediawiki-nginx.conf from template, for http://box{{ mediawiki_url }} + template: + src: mediawiki-nginx.conf.j2 + dest: "{{ nginx_config_dir }}/mediawiki-nginx.conf" + when: mediawiki_enabled + +- name: Remove mediawiki-nginx.conf if not mediawiki_enabled (debuntu) + file: + path: "{{ nginx_config_dir }}/mediawiki-nginx.conf" + state: absent + when: not mediawiki_enabled and is_debuntu + +- name: Restart nginx service to enable/disable http://box{{ mediawiki_url }} + systemd: + name: nginx + daemon_reload: yes + state: restarted + - name: Add 'mediawiki' variable values to {{ iiab_ini_file }} ini_file: path: "{{ iiab_ini_file }}" diff --git a/roles/mediawiki/tasks/install.yml b/roles/mediawiki/tasks/install.yml index 884ab7497..0ab0acbff 100644 --- a/roles/mediawiki/tasks/install.yml +++ b/roles/mediawiki/tasks/install.yml @@ -25,6 +25,12 @@ mode: 0755 keep_newer: yes +- name: Create symlink mwlink from docroot to {{ mediawiki_abs_path }} + file: + src: "{{ mediawiki_abs_path }}" + dest: "{{ doc_root }}/mwlink" + state: link + - name: Start MySQL service, so we can create db service: state: started @@ -51,7 +57,7 @@ --installdbpass={{ mediawiki_db_user_password }} --dbuser={{ mediawiki_db_user }} --dbpass={{ mediawiki_db_user_password }} - --scriptpath=/mediawiki + --scriptpath=/mwlink --lang=en --pass={{ mediawiki_admin_user_password }} "{{ mediawiki_site_name }}" @@ -60,11 +66,25 @@ chdir: "{{ mediawiki_abs_path }}" creates: "{{ mediawiki_abs_path }}/LocalSettings.php" +- name: Configure wgArticlePath variable in {{ mediawiki_abs_path }}/LocalSettings.php + lineinfile: + dest: "{{ mediawiki_abs_path }}/LocalSettings.php" + line: '$wgArticlePath = "/wiki/$1";' + create: yes + +- name: Configure wgUsePathInfo variable in {{ mediawiki_abs_path }}/LocalSettings.php + lineinfile: + dest: "{{ mediawiki_abs_path }}/LocalSettings.php" + line: '$wgUsePathInfo = true;' + create: yes + - name: Install /etc/{{ apache_config_dir }}/mediawiki.conf from template, for http://box{{ mediawiki_url }} template: src: mediawiki.conf.j2 dest: "/etc/{{ apache_config_dir }}/mediawiki.conf" +# Install {{ nginx_config_dir }}/mediawiki-nginx.conf from template in enable.yml + - name: Add 'mediawiki_installed' variable values to {{ iiab_state_file }} lineinfile: dest: "{{ iiab_state_file }}" diff --git a/roles/mediawiki/templates/mediawiki-nginx.conf.j2 b/roles/mediawiki/templates/mediawiki-nginx.conf.j2 new file mode 100644 index 000000000..47704e4cb --- /dev/null +++ b/roles/mediawiki/templates/mediawiki-nginx.conf.j2 @@ -0,0 +1,54 @@ +# this works if (docroot)/mwlink links to install +# and LocalSettings.php has +# $wgScriptPath = "/mwlink"; +# $wgArticlePath = "/wiki/$1"; +# $wgUsePathInfo = true; + +location ~ ^/mwlink/(index|load|api|thumb|opensearch_desc)\.php$ { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass php; # or whatever port your PHP-FPM listens on +} + +# Images +location /mwlink/images { + # Separate location for images/ so .php execution won't apply +} +location /mwlink/images/deleted { + # Deny access to deleted images folder + deny all; +} +# MediaWiki assets (usually images) +location ~ ^/mwlink/resources/(assets|lib|src) { + try_files $uri 404; + add_header Cache-Control "public"; + expires 7d; +} +# Assets, scripts and styles from skins and extensions +location ~ ^/mwlink/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg)$ { + try_files $uri 404; + add_header Cache-Control "public"; + expires 7d; +} + + +## Uncomment the following code if you wish to use the installer/updater +## installer/updater +#location /mwlink/mw-config/ { +# # Do this inside of a location so it can be negated +# location ~ \.php$ { +# include /etc/nginx/fastcgi_params; +# fastcgi_param SCRIPT_FILENAME $document_root/mwlink/mw-config/$fastcgi_script_name; +# fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on +# } +#} + +# Handling for the article path (pretty URLs) +location {{ mediawiki_url }}/ { + rewrite ^{{ mediawiki_url }}/(?.*)$ /mwlink/index.php; +} + +# Explicit access to the root website, redirect to main page (adapt as needed) +location = {{ mediawiki_url }} { + return 301 {{ mediawiki_url }}/Main_Page; +} From cdef90d1a53a56f2cdf2c17b6c84fa98a7c538e7 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 13:27:15 -0500 Subject: [PATCH 3/7] comment out wp and mw from proxy list --- roles/nginx/tasks/uses_apache.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/roles/nginx/tasks/uses_apache.yml b/roles/nginx/tasks/uses_apache.yml index f24afcb49..5eaec381f 100644 --- a/roles/nginx/tasks/uses_apache.yml +++ b/roles/nginx/tasks/uses_apache.yml @@ -25,13 +25,21 @@ dest: "/etc/nginx/conf.d/lokole-nginx.conf" when: lokole_enabled -- name: Install MediaWiki's nginx conf.d file from template - template: - src: mediawiki-nginx.conf.j2 - dest: /etc/nginx/conf.d/mediawiki-nginx.conf - when: mediawiki_enabled +# mediawiki and wordpress are no longer proxied -- name: Install WordPress's nginx conf.d file from template +#- name: Install MediaWiki's nginx conf.d file from template +# template: +# src: mediawiki-nginx.conf.j2 +# dest: /etc/nginx/conf.d/mediawiki-nginx.conf +# when: mediawiki_enabled + +#- name: Install WordPress's nginx conf.d file from template +# template: +# src: wordpress-nginx.conf +# dest: /etc/nginx/conf.d/ +# when: wordpress_enabled + +- name: Install Nextcloud's nginx conf.d file from template template: src=nextcloud-nginx.conf dest=/etc/nginx/conf.d/nextcloud-nginx.conf when: nextcloud_enabled @@ -44,11 +52,5 @@ mode: 0666 when: nodered_enabled -- name: Install WordPress's nginx conf.d file from template - template: - src: wordpress-nginx.conf - dest: /etc/nginx/conf.d/ - when: wordpress_enabled - #- name: Install proxpass to apache running on localhost From 35ac04ea3be192f932d5dd7a880f827acfc14f3a Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 13:41:34 -0500 Subject: [PATCH 4/7] fix glitch in osm-vector-maps-nginx.conf --- roles/osm-vector-maps/templates/osm-vector-maps-nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/osm-vector-maps/templates/osm-vector-maps-nginx.conf b/roles/osm-vector-maps/templates/osm-vector-maps-nginx.conf index 8b5813b63..035ebb651 100644 --- a/roles/osm-vector-maps/templates/osm-vector-maps-nginx.conf +++ b/roles/osm-vector-maps/templates/osm-vector-maps-nginx.conf @@ -1,6 +1,6 @@ # For downloadable regional vector tilesets location /maps { - rewrite ^/maps/(.*)$ /osm-vector-maps/$1; + rewrite ^/maps(.*)$ /osm-vector-maps$1; } location /osm-vector-maps { alias /library/www/osm-vector-maps; From 5464f91f57a345688f7add5e3b51b91a70d2b1e3 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 14:05:34 -0500 Subject: [PATCH 5/7] fix awstats redirect to cgi without host --- roles/awstats/templates/awstats-nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/awstats/templates/awstats-nginx.conf b/roles/awstats/templates/awstats-nginx.conf index 1f337c297..c67c4c0fd 100644 --- a/roles/awstats/templates/awstats-nginx.conf +++ b/roles/awstats/templates/awstats-nginx.conf @@ -1,5 +1,5 @@ location ~ ^/awstats { - rewrite ^ http://box.lan/cgi-bin/awstats.pl?config=schoolserver; + rewrite ^ /cgi-bin/awstats.pl; } location ^~ /awstatsicons { alias /usr/share/awstats/icon/; From 131bff8362d058bc096f397cf21c53667bd4ba49 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Sun, 29 Dec 2019 17:49:42 -0500 Subject: [PATCH 6/7] change dokuwiki url --- vars/default_vars.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/default_vars.yml b/vars/default_vars.yml index 9ea48c12e..4d29a3252 100644 --- a/vars/default_vars.yml +++ b/vars/default_vars.yml @@ -338,7 +338,7 @@ azuracast_port_range_prefix: 10 dokuwiki_install: False dokuwiki_enabled: False -dokuwiki_url: /wiki +dokuwiki_url: /dokuwiki mediawiki_install: False mediawiki_enabled: False From e4eda59ad5706e49fea138cd06edfe401937cec0 Mon Sep 17 00:00:00 2001 From: Tim Moody Date: Mon, 30 Dec 2019 10:06:39 -0500 Subject: [PATCH 7/7] formatting --- roles/nginx/tasks/uses_apache.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/nginx/tasks/uses_apache.yml b/roles/nginx/tasks/uses_apache.yml index 5eaec381f..91bf27e4a 100644 --- a/roles/nginx/tasks/uses_apache.yml +++ b/roles/nginx/tasks/uses_apache.yml @@ -40,7 +40,9 @@ # when: wordpress_enabled - name: Install Nextcloud's nginx conf.d file from template - template: src=nextcloud-nginx.conf dest=/etc/nginx/conf.d/nextcloud-nginx.conf + template: + src: nextcloud-nginx.conf + dest: /etc/nginx/conf.d/nextcloud-nginx.conf when: nextcloud_enabled - name: Install NodeRed's nginx conf.d file from template @@ -53,4 +55,4 @@ when: nodered_enabled #- name: Install proxpass to apache running on localhost - +