I have my main site at x.com (@ /var/www/x.com/index.html)
# MAIN LOCATION location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; #autoindex on; proxy_set_header X-Real-IP $remote_addr; } I want /v2 to redirect to another local dir (@ /var/www/x.com/v2/public/index.html)
# Redirect beta site location /v2 { alias /var/www/x.com/v2/public; } This seems like it should work, but instead, it's going to my 404 site. Not sure if this matters, but here is my root above both of them:
# path root /var/www/throneoflies.com/html; I tried ordering "/v2" both above "/" and below - didn't seem to make a difference. I read I shouldn't use 'root' instead of 'alias' because it's a different schema (/v2/public/ and not just /v2/).
EDIT: Seems like it should be working - I've read a lot since this post. Here is my full file:
server { # MAIN >> # SSL configuration listen 443 default_server ssl; server_name www.x.com; error_page 404 /error/404.html; server_tokens off; # SSL ssl_certificate /etc/ssl/x.com/cert.pem; ssl_certificate_key /etc/ssl/x.com/key.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #ssl_session_tickets off; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; # path root /var/www/x.com/html; #root /var/www/x.com/v2/public; #works! # Add index.php to the list if you are using PHP #index index.php index.html index.htm index.nginx-debian.html; index index.html; # 404 handling - no cache location = /404.html { add_header Cache-Control "no-cache" always; } # Redirect beta site : Why doesn't it work if the outer block root changed to the same path works? I can REPLACE my "/" with this v2 path np. However, alias at /v2 does not work. location = /v2 { alias /var/www/x.com/v2/public; #root /var/www/x.com/v2/public; #try_files $uri $uri/ =404; } # MAIN LOCATION location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; #autoindex on; proxy_set_header X-Real-IP $remote_addr; # DENY .HTACCESS ACCESS location ~/\.ht { deny all; } }
location /v2block seems fine. Does/v2redirect to/v2/before the 404 response? Is there anindexdirective in the outer block?index index.html;error_page 404 /error/404.html;). Also, if I swap the main root with the alias I'm trying to do, the /v2/public/ site loads FINE! So it's not a path issuelocation = /v2which is not the same as your original question (and will definitely not work)