Hi,
I am trying to optimise our site for SEO, starting with password protection of our staging server, to avoid duplicate content issues.
I decided that an update to our Trellis configuration would be the best tactic to avoid plugin inefficiency, bloat etc, since it only involves a modification to Nginx configuration.
Configuring Nginx manually for the password protection works. I just have to get it working with Trellis.
So:
- Added the following to group_vars/staging/main.yml:
nginx_includes_templates_path: nginx-includes-staging
- Created file nginx-includes-staging/australiascience.tv/assets-expiry.conf.j2, with this content:
location / {
try_files $uri $uri/ /index.php?$args;
auth_basic “closed_site”;
auth_basic_user_file conf.d/.htpasswd;
}
- Also added the file nginx-includes/australiascience.tv/assets-expiry.conf.j2, ready for the next thing I have to do. The idea is that nginx-includes/ will be used as the default, to be used by production. I can’t see any evidence that it’s causing a problem.
- Reprovisioned:
ansible-playbook server.yml -e env=staging
resulting in the usual (correct) output, but concluding with:
RUNNING HANDLER [common : reload nginx] ************************************************************************************************************************
System info:
Ansible 2.4.0.0; Linux
Trellis at “Updatevagrant_box_version
to>= 201801.02.0
”non-zero return code
nginx: [emerg] duplicate location “/” in /etc/nginx/sites-
enabled/australiascience.tv.conf:54
nginx: configuration file /etc/nginx/nginx.conf test failed
fatal: [35.201.10.255]: FAILED! => {“changed”: true, “cmd”: [“nginx”, “-t”], “delta”: “0:00:00.020786”, “end”: “2018-02-01 02:51:49.501284”, “failed”: true, “rc”: 1, “start”: “2018-02-01 02:51:49.480498”, “stderr_lines”: [“nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/australiascience.tv.conf:54”, “nginx: configuration file /etc/nginx/nginx.conf test failed”], “stdout”: “”, “stdout_lines”: }
to retry, use: --limit @/home/mclarke/gitlab/australiascience.tv/trellis/server.retryPLAY RECAP *****************************************************************************************************************************************************
35.201.10.255 : ok=91 changed=8 unreachable=0 failed=1
localhost : ok=0 changed=0 unreachable=0 failed=0~/gitlab/australiascience.tv/trellis$
On the server in /etc/nginx/sites-available/australiascience.tv.conf, it seems that the problem is here:
. . .
include includes.d/australiascience.tv/*.conf;location ~* /app/uploads/.*.php$ {
deny all;
}location / {
try_files $uri $uri/ /index.php?$args;
}
. . .
and, of course, includes.d/australiascience.tv/assets-expiry.conf contains this:
location / {
try_files $uri $uri/ /index.php?$args;
auth_basic “closed_site”;
auth_basic_user_file conf.d/.htpasswd;
}
thus causing the duplicate entry.
This is probably a silly mistake on my part, but so far I can’t spot it. Note that I previously tried with “–tags nginx-includes” but the same thing happened.
It will be great if I can get this working, because I can then do something similar to enable our assets to leverage browser caching, one of the things we have to achieve to appease Google Page Insights.
Note also that I have just rebased our Trellis fork from your master branch, hoping it would solve the problem, but no joy.
Hoping you can advise! Thanks in advance.