2016-08-10 6 views
0

私はドキュメントを読んでいて、Nginxを使ってリクエストをプロキシする方法について数多くの例を見てきましたが、まだ簡単な例を作ることはできません。
http://localhost:5050/maps/のようなURLを入力すると、NginxがそのURLをGoogleマップに要求します。
は、ここに私の設定ファイルです:リクエストをNginxにリダイレクトする方法

#user nobody; 
worker_processes 1; 

#error_log logs/error.log; 
#error_log logs/error.log notice; 
#error_log logs/error.log info; 

#pid  logs/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  mime.types; 
    default_type application/octet-stream; 

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
    #     '$status $body_bytes_sent "$http_referer" ' 
    #     '"$http_user_agent" "$http_x_forwarded_for"'; 

    #access_log logs/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 

    #gzip on; 

    server { 
     listen  5050; 
     server_name localhost; 

     #charset koi8-r; 

     #access_log logs/host.access.log main; 

     location/{ 
      #root html; 
      #index index.html index.htm; 
      #access_log off; 
      proxy_pass http://maps.googleapis.com; 
      proxy_pass_request_body on; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header Host $host; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     } 
    } 
} 

しかし、私はhttp://localhost:5050/maps/にリクエストを作るとき...、私は404ページが見つかりません「」標準です。
error.logファイルに「システムが指定されたファイルを見つけることができません」という複数のエントリが表示されます。これは奇妙です - ディスクからファイルを要求しませんでした。
さらに、私はFiddlerを参照しました。maps.googleapis.comへの送信リクエストはありません。
ここで何が間違っていましたか?サンプルURLはhttp://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA

答えて

1

です。私は正しくnginxを再起動していなかったと思います(私はWindowsです)ので、シャットダウンすると、依然としてnginx.exeが処理を続行していました。
はとにかく、ここで私の作品バージョンです:; `Googleにホストヘッダーとして「ローカルホスト」を送っているだろう` proxy_set_headerホスト$ホスト:

worker_processes 1; 

error_log logs/error.log; 
pid  logs/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  mime.types; 
    default_type application/octet-stream; 

    sendfile  on; 

    keepalive_timeout 2000; 

    server { 
     listen  5050; 
     server_name localhost; 

     location/{ 
      proxy_pass https://maps.googleapis.com; 
      proxy_pass_request_body on; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     } 
    } 
} 
+0

があなたの元での問題は、この行でした。あなたの新しいものはその行を持っていないように見えます。 –

+0

@JoshuaDeWald私はそれに気づいた。それは重要ですか? Googleは私を認識しませんか? :) – chester89

+0

Googleのウェブサーバーがホストヘッダーを無視していない限り(たとえば、ホストが1つだけの場合)、404などのエラーが発生する可能性があります。 –

関連する問題