私はNginxエイリアスリダイレクトが機能しないのはなぜですか(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;
}
(/var/www/x.com/index.html @)私は@(/V2は別のローカルディレクトリにリダイレクトしたいx.comで私のメインのサイトを持っています/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の」の両方を注文してみました - 違いを確認していないようでした。私は別のスキーマ(/ v2/public /だけではなく、/ v2 /)であるため、 '別名'の代わりに 'root'を使用しないでください。
編集:これはうまくいくはずです。この記事以降はたくさん読んでいます。ここに私の完全なファイルは次のとおりです。
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/siteはFINEを読み込みます!それはパスの問題ではありません –