The forum flagged my original response as spam. I am trying to avoid that.
That sucks . I wanted to have another look on your playbook. Meh.
Permission denied sounds like a file/directory permissions thing. The permissions on /home/abdul/static_site/ are currently set to rwxr-xr-x. That sounds okay right?
Check owner:group of the files, current, and parent folders. The account running nginx processes should own those files, which also means have access on the complete path. It’s usually root, at least for master process, so files access should be fine, but I’m wondering who owns those files.
I wanted to check again your “copy contents of site” task, see if you also have the ansible_user=root
directive defined on this one. On my end, I removed these as I’m connecting with another user, and have become: true
on play level, which by default run tasks as root using sudo
, so no need to specify it except if you had to connect with root prior to privilege escalation.
Just checked and you had become_user: root
, not ansible_user
defined on your tasks, except for the one you use to deploy your static site files. So not the same thing, but it shouldn’t matter except if you defined another user for become_user
somewhere else. In doubt, try to add become_user: root
to this task and inspect copied files for a potential ownership change.
If I’m not missing something, it shouldn’t change anything, though you might want to specify ownership parameters for copied files on task args as precaution:
- name: copy contents of site
copy:
src: /home/ptn/TEMP/test_nginx/static_site_src/
dest: /home/ansible/static_site
owner: root
group: root
Could you run this command and paste the output: tree -augp /home/abdul/static_site/
on your nginx node ?
Please I only have rudimentary knowledge of Nginx. Would you be so kind to demonstrate with an example?
I’m sorry. I was suggesting you change this line from your vhost config (static_site.cfg here): try_files $uri $uri/ =404;
to try_files $uri $uri/ =<anotherHttpCode>;
(without ‘<’ and ‘>’). This way, you could tell if the 404/HTTP returned code is a legit 404 or the one you set up on your try_files
directive.
And now we know you get a 404 because Nginx can’t access $uri
or files under.
All suggestions are welcome
<3
Well, a few things I think I can take away from your response is that I set up my play book correctly and that your replication of my set up returned the page with the Ansible logo, meaning that in my set up the problem is not with ansible but lies entirely within Nginx. Am I correct?
Yes. Well, not really Nginx as your issue is about files access, though Ansible did its job here.
I actually tried twice. Once using lynx on WSL. The other using firefox running off the Windows host. Only the lynx test showed up in the access log. I wonder why?
AFAIK default behavior is: HTTP clients request are logs in access.log and errors (not requests) only in error.log. They are not mutually exclusive, a failed request will still appear in access.log, and related errors will be in error.log. Though you can change log format and such.
Now you mention requests from a Firefox browser on your Windows host and it seems to me your Windows host couldn’t join your Nginx instance. I don’t remember well enough your name resolution config, but it might be possible you only added your website hostname in WSL /etc/hosts file and not in the counterpart file on your Windows machine.
IIRC, WSL /etc/hosts file is by default generated from Windows config (I might be wrong, I haven’t used WSL for a long time), but the opposite is not true.
Anyways, keep me posted !