2016-07-27 2 views
0

my.personal.ip.addressを含むすべてのユーザーをリダイレクトしますが、私以外のユーザーをブログにリダイレクトすることになっています。デフォルトのnginxファイルに入れたときに動作していましたが、今ではノードアプリケーションを実行しようとしていますが、if文をどこに置くのが不思議で、なぜ動作しないのかは分かりません。Nginxのリダイレクトルールはノードアプリケーションでは機能しません

# the IP(s) on which your node server is running. I chose port 3000. 
upstream mywebsite { 
    server 127.0.0.1:3000; 
    keepalive 8; 
} 

# the nginx server instance 
server { 
    listen 0.0.0.0:80; 
    server_name mywebsite.ca mywebsite; 
    access_log /usr/share/nginx/html/yourdomain.log; 


    # pass the request to the node.js server with the correct headers 
    # and much more can be added, see nginx config options 
    location/{ 

     proxy_set_header X-Real-IP $remote_addr; 



     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_set_header X-NginX-Proxy true; 

     proxy_pass http://mywebsite/; 

     if ($remote_addr != my.personal.ip.address){ 
     rewrite^http://blog.mywebsite.ca; 
    } 

     proxy_redirect off; 
    } 
} 

答えて

1

ノードアプリケーションも127.0.0.1でリッスンしていますか?

http.createServer(function (req, res) { 
    res.writeHead(200, {'Content-Type': 'text/plain'}); 
    res.end('Hello World\n'); 
}).listen(3000, "127.0.0.1"); 
+0

ノードアプリケーションが表示されているかどうかわかりません。私が抱えている問題は、ifステートメントのためにブログにリダイレクトされるはずがないということですが、私はそうです。 –

+0

申し訳ありませんが、私はよく理解しました。たぶん、NGINXのデバッグをアクティブにするのが最善の方法です。例: 'error_log/path/to/log debug;'この[IfIsEvil](https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/)を参照してください。 –

関連する問題