I have a reverse proxy (80/443) and a back-end application (8015/44315). Both run on nginx.
The reverse dynamic vhost works fine but I have an little issue with a classic static vhost...
rp vhost conf:
server {
listen 443 ssl;
server_name domain.tld;
ssl_certificate /usr/local/etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /usr/local/etc/letsencrypt/live/domain.tld/privkey.pem;
return 301 https://www.$host$request_uri$is_args$query_string;
}
server {
listen 443 ssl;
server_name www.domain.tld;
ssl_certificate /usr/local/etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /usr/local/etc/letsencrypt/live/domain.tld/privkey.pem;
access_log /var/log/nginx/access_domain.tld.log combined;
error_log /var/log/nginx/error_domain.tld.log;
location / {
proxy_pass http://192.168.0.15:8015/;
proxy_redirect default;
proxy_set_header Host $host;
}
}
backend vhost conf:
server {
listen 8015;
server_name www.domain.tld;
root /usr/local/www/domain;
access_log /var/log/nginx/access_domain.tld.log combined;
error_log /var/log/nginx/error_domain.tld.log;
include /usr/local/etc/nginx/snippets/generic.conf;
location / {
alias /usr/local/www/nginx/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /pub {
alias /usr/local/www/domain/pub;
allow all;
autoindex off;
}
location /static {
alias /usr/local/www/domain/static;
autoindex on;
fancyindex on;
fancyindex_exact_size off;
}
location /vid {
alias /usr/local/www/domain/vid;
autoindex on;
fancyindex on;
fancyindex_exact_size off;
allow all;
}
}
First look, everything should be works. However...
$ curl -I https://www.domain.tld/
HTTP/1.1 200 OK
Ok!
$ curl -I https://www.domain.tld/pub/
HTTP/1.1 403 Forbidden
OK!
$ curl -I https://www.domain.tld/pub/file.txt
HTTP/1.1 200 OK
Awesome!
And now... without /
$ curl -I https://www.domain.tld/pub
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 20 Nov 2016 19:04:03 GMT
Content-Type: text/html
Connection: keep-alive
Location: http://www.domain.tld:8015/pub/
Why without the trailing / I have this "redirection" to backend port 8015? How can I solve that ?