2017-06-13 17 views
1

私は私の接続を暗号化するためにLetsEncryptでtogheter Webサーバーとしてnginxのを使用しています。 私のホームページ等、www.domain.com、mail.domain.comのように、複数のサブドメインを持っている は、今私は特別なルートフォルダにすべての「/.well-known」接続をリダイレクトします。Nginx - 間違ったリダイレクト?

私は私が正しい設定を持っていると思うが、結果は私が欲しいものではありません。

ここに私のconfigs:

default.vhost

#============================================= 
#== Server 
#============================================== 

server { 

     #============================================= 
     #== General 
     #============================================= 

     # Port 
     listen 80; 

     # Server name 
     #server_name _; 

     #============================================= 
     #== Locations 
     #============================================= 

     location /.well-known { 
       #default_type "text/plain"; 
       root /var/wwww/LetsEncrypt; 
     } 

     location/{ 
       return 301 https://www.example.com$request_uri; 
     } 
} 


server { 

     #============================================= 
     #== General 
     #============================================= 

     # Port 
     listen 443 ssl; 

     # Server name 
     #server_name _; 

     #============================================= 
     #== Locations 
     #============================================= 

     location/{ 
       return 301 https://www.example.com$request_uri; 
     } 
} 

www.domain.com

#============================================= 
#== HTTP-Server 
#============================================= 

server { 

     #============================================= 
     #== General 
     #============================================= 

     # Port 
     listen 443 ssl default_server; 

     # Server name 
     server_name www.example.com; 

     # Root folder 
     root /var/www/www.example.com/web/; 

     # Order of index files 
     index index.php index.html index.htm; 

     #============================================= 
     #== Includes 
     #============================================= 

     # SSL configuration 
     include /etc/nginx/ssl.conf; 

     # PHP configuration 
     include /etc/nginx/php.conf; 

     #============================================= 
     #== Locations 
     #============================================= 

     location /.well-known/acme-challenge { 
       #default_type "text/plain"; 
       root /var/wwww/LetsEncrypt; 
     } 

     location/{ 
       try_files $uri $uri/ =404; 
     } 

     location ~ /\.ht { 
       deny all; 
     } 
} 

mail.domain.com

#============================================= 
#== HTTP-Server 
#============================================= 

server { 

     #============================================= 
     #== General 
     #============================================= 

     # Port 
     listen 443 ssl; 

     # Server name 
     server_name mail.example.com; 

     # Root folder 
     root /var/www/mail.example.com/web/; 

     # Order of index files 
     index index.php index.html index.htm; 

     #============================================= 
     #== Includes 
     #============================================= 

     # SSL configuration 
     include /etc/nginx/ssl.conf; 

     # PHP configuration 
     include /etc/nginx/php.conf; 

     #============================================= 
     #== Locations 
     #============================================= 

     location/{ 
       try_files $uri $uri/ =404; 
     } 

     location ~ /\.ht { 
       deny all; 
     } 
} 

だから、何が... mail.domain.comとwww.domain.comは素晴らしい作品が起こります。 問題はよく知られているルールです。 Nginxはそれを無視していますが、 "/ var/www/LetsEncrypt"からファイルを取得する代わりに、常にリダイレクトされます。

私はDEFAULT_SERVERが問題であると思ったが、「default.vhost」何も(...も少し奇妙に聞こえる何..常に404)作業していないし、それを移動した後。

私はあなたたちが私を助けることができる:(

種類については、 アンドレアスは

答えて

0

まず、あなたが指定したディレクトリから始まるすべての要求をキャプチャしますどのnginx 'location begins with' modifier ^~を使いたいいただければ幸いです。

location ^~ /.well-known/acme-challenge { 

第2に、/var/www/LetsEncryptではなく、/var/wwww/LetsEncryptがあります。

あなたの場所ブロックは次のようになります。

location ^~ /.well-known/acme-challenge { 
    #default_type "text/plain"; 
    root /var/www/LetsEncrypt; 
} 

をもrootとしてaliasとルートの違いを意識するが、例えば、パスにURIを追加します:

alias /var/www/LetsEncrypt; # Will serve files from /var/www/LetsEncrypt 

root /var/www/LetsEncrypt; # Will serve files from /var/www/LetsEncrypt/.well-known/acme-challenge 

これがあなたをつまずかせるかもしれませんあなたが特定のディレクトリを提供しようとしている場合。

+0

さて、私は後でそれをしようとします。 速い返信ありがとう:) – Andreas

+0

だから、私は変更をテストして、それは完璧に動作します! "ルート"の代わりに "エイリアス"だけが機能しませんでしたが、大きな問題はありません。私はあなたの答えを受け入れられた答えとして設定します! – Andreas

関連する問題