2016-07-27 14 views
1

私はnginxを新しくして、自分のサイトを動作させることができません(AWSのCakephpサイト)。私はメッセージが「ページは適切にリダイレクトされていません」、何かがドメインをそれ自体に追加する方法(リダイレクトループ)を取得しています。nginx cakephp仮想ホストリダイレクト

例私は自分のサイトにsub1.mysite.comと入力すると、ブラウザにはsub1.mysite.com/sub1.mysite.com/sub1.mysite.com/sub1.mysite.comなどが追加されます。

ここに私のサイトで入手可能なコンフィグ

server { 
    listen 80; 
    server_name sub1.mysite.com; 
    rewrite ^(.*) http://sub1.mysite.com$1 permanent; 
} 

server { 
    listen 80; ## listen for ipv4; this line is default and implied 
    server_name name sub1.mysite.com; 
    root /var/www/sub1.mysite.com/public_html/sub-root; 
    index index.php index.html index.htm; 

    # error_page 404 errors/404.html; 
    access_log /var/log/nginx/sub1.mysite.com.access.log; 

    # Make site accessible from http://localhost/ 
    location/{ 
     try_files $uri $uri/ /index.php?$uri&$args; 
    } 
    location ~ .php$ { 
     root /var/www/sub1.mysite.com/public_html/sub-root; 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

は私が間違ってやっている任意のアイデアですか?

答えて

0

あなたの問題は、あなたの最初のnginxサーバディレクティブである:

server { 
    listen 80; 
    server_name sub1.mysite.com; 
    rewrite ^(.*) http://sub1.mysite.com$1 permanent; 
} 

あなたのディレクティブは、ポート80(HTTP)でリッスンしているとsub1.mysite.comに応答し、それは$1が結果であるhttp://sub1.mysite.com$1 permanentにすべて^(.*)と一致し、リダイレクトあなたのマッチングの基本的にそれは、sub1.mysite.comを追加します。私はあなたがこのサーバー指令を必要とする理由は何も見ませんか?あなたのメインサーバディレクティブと同じポートをリッスンし、同じものに応答しますserver_nameただ削除してください。結果は、(詳細はノートを見て、私はいくつかの設定を固定に注意してください)のようになります。

server { 
    listen 80; ## listen for ipv4; this line is default and implied 
    server_name sub1.mysite.com; # removed the redundant 'name' keyword that you used here 
    root /var/www/sub1.mysite.com/public_html/sub-root; 

    index index.php index.html index.htm; 

    charset utf-8; # added this, you don't have to. 

    # error_page 404 errors/404.html; 
    access_log /var/log/nginx/sub1.mysite.com.access.log; 

    # edited this. Given the request to `sub1.mysite.com` it will 
    # try to first match the file itself, than an index file in the root 
    # directory and then it will just send the request to index.php with the query string 
    # which means the request to sub1.mysite.com/dashboard will be forwarded 
    # to sub1.mysite.com/index.php/dashboard 
    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
    } 

    # added both of these lines, you don't have to. they are just good practice. 
    # If you don't add them your log files will get bloated real fast. 
    # these files are requested by crawlers. 
    location = /favicon.ico { access_log off; log_not_found off; } 
    location = /robots.txt { access_log off; log_not_found off; } 

    location ~ \.php$ { # added a '\' 
     # removed redundant 2 lines here 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

あなたが最初のサーバディレクティブのためにあなたの心の中で別の平均を持っていた場合、私に知らせてください。

+0

2日前はどこでしたか...ただ冗談を言っています:-)。真剣に、ありがとう。その作業!しかし、私が今行っている唯一の問題は 'index.php'です。navの 'pretty urls'をクリックすると動作します; ex:' sub1.mysite 'というダッシュボードをクリックします。 com \ dashboard'、それは正常に転送します。私が直接インデックスに行くと、うまく 'sub1.mysite.com/index.php'が動作します。しかし、サイトに移動してインデックスファイル(sub1.mysite.com)を指定しないとエラーが表示される** "Missing Controller Error:Sub1.mysite.comControllerが見つかりませんでした。ケーキのコントローラーにドメイン名を渡すように見えます。アイデア? – user20719

+0

@ user20719私の編集した答えをチェックしてください。あなたが得ているエラーはCakePHPエラーですか?私はCakePHPを使ったことが一度もありません。とにかく、それがCakePHPエラーなら、あなたのnginx設定はおそらくOKですが、ルート宣言に問題があります。あなたのルータを見てみましょう – kfirba