Open ScuttleSE opened 7 years ago
Does an example.se
conf file get created in /etc/nginx/sites-available
?
Indeed it does, a large one
What happens if you set a root
path?
Well, in the generated conf-file in sites-enabled there is a root set, in this case to root /usr/share/nginx/html;
Yeah but you can set the root
value on your virtual host too (with the path of your site instead).
Example:
example.se:
domains: ['example.se', 'www.example.se']
root: '/path/to/your/root'
default_server: False
upstreams:
- name: 'example'
servers: ['hostname_of_internal_server:80']
But since I don't have a root on the nginx-server, what should I set it to? My upstream is on another machine.
How did you have your nginx config set up before using this role? Paste it here and I'll take a look at it tonight.
The old config was a huge, ugly monolithic conf, can I email it instead?
In essence, all the hosts I was running with the old config had this:
location / {
proxy_pass http://upstream_server;
proxy_set_header Host $host;
}
That was it, no root
The Problem is the =404
at the end of the try_files
.
Adding this in group_vars/app.yml
fixed the problem for me:
custom_root_location_try_files: '$uri @example'
Note: the @example
is generated, it is the name of your upstream entry, if you have multiple add all of them here. This seems to be fixed in https://github.com/nickjj/ansible-nginx/pull/9
Thanks. This role is on my radar for getting an overhaul. I will definitely address this.
Going to keep this open until it's merged.
Yeah, including both an @upstream and =404 in the try_files
line doesn't make sense. Only the very last parameter is used as a fallback (http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files)
Also, sometimes it is desirable to proxy all requests to the upstream server (like in @ScuttleSE's snippet) instead of using try_files
at all.
I've tried to address both of these issues here: https://github.com/nickjj/ansible-nginx/pull/19
Got a site defined like this:
When accessing it I end up with the default nginx-page from /usr/share/nginx/html instead of being forwarded to my upstream-server