【发布时间】:2017-10-12 10:01:10
【问题描述】:
我的主站点位于 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;
}
我希望 /v2 重定向到另一个本地目录 (@/var/www/x.com/v2/public/index.html)
# Redirect beta site
location /v2 {
alias /var/www/x.com/v2/public;
}
这似乎应该可以工作,但它会转到我的 404 站点。不确定这是否重要,但这是我的根:
# path
root /var/www/throneoflies.com/html;
我尝试在 "/" 上方和下方订购 "/v2" - 似乎没有什么不同。我读到我不应该使用“root”而不是“alias”,因为它是不同的架构(/v2/public/ 而不仅仅是/v2/)。
编辑: 似乎它应该可以工作 - 自从这篇文章以来我已经阅读了很多。这是我的完整文件:
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 /v2块似乎没问题。/v2是否在 404 响应之前重定向到/v2/?外部块中有index指令吗? -
我没有看到可见的重定向,如果这就是你的意思。索引指令?是的,只是
index index.html; -
(这是 CAUGHT 404,而不是来自外部
error_page 404 /error/404.html;的丑陋 nginx 404)。另外,如果我用我想要做的别名交换主根目录,/v2/public/ 站点会加载 FINE!所以这不是路径问题 -
@RichardSmith 我在上面添加了我的完整文件
-
您的 EDIT 显示
location = /v2这与您的原始问题不同(而且肯定不会起作用)