2017-09-20 16 views
0

私はアプリを稼働させています アプリが完璧に稼動しています。ルートURLにアクセスできます。しかし、他のURLにアクセスできません。アプリケーションはnodejs expressフレームワークで構築されています。私のサーバーOSはUbuntu 17です。 http://35.202.2.217で私のアプリを実行する必要があります。それは私がプロキシパスを使用している理由です。私はここで立ち往生している。私はnginxのを使用していますhttp://localhost:1336/pagesnodejs Appとnginxのサーバー設定

、例えば

を行うには何を持っています。

私のnginxのコード

upstream adshackers { 
     server 10.128.0.2:8082; 
     server 10.128.0.2:9082; 
     server 10.128.0.2:3082; 
} 

server { 
     listen 80 default_server; 
     listen [::]:80 default_server; 
     # SSL configuration 
     # 
     # listen 443 ssl default_server; 
     # listen [::]:443 ssl default_server; 
     # 
     # Note: You should disable gzip for SSL traffic. 
     # See: https://bugs.debian.org/773332 
     # 
     # Read up on ssl_ciphers to ensure a secure configuration. 
     # See: https://bugs.debian.org/765782 
     # 
     # Self signed certs generated by the ssl-cert package 
     # Don't use them in a production server! 
     # 
     # include snippets/snakeoil.conf; 
     root /var/www/html; 
     # Add index.php to the list if you are using PHP 
     index index.php index.html index.htm index.nginx-debian.html; 
     server_name adshackers.com; 
     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
     proxy_pass http://adshackers/; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection 'upgrade'; 
     proxy_set_header Host $host; 
     proxy_cache_bypass $http_upgrade; 


       try_files $uri $uri/ =404; 
     } 
     # pass PHP scripts to FastCGI server 
     # 
     location ~ \.php$ { 
       include snippets/fastcgi-php.conf; 
       # With php-fpm (or other unix sockets): 
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
       # With php-cgi (or other tcp sockets): 
     #  fastcgi_pass 127.0.0.1:9000; 
     } 
     # deny access to .htaccess files, if Apache's document root 
     # concurs with nginx's one 
     # 
     location ~ /\.ht { 
       deny all; 
     } 
} 
+0

'proxy_pass http:// adshackers /;'から 'proxy_pass'を' http:// adshackers'にしてください。 – nilobarp

+0

はテールスラッシュとPHP部分を取り除きました。 ..thanks –

答えて

0

だから私はそれを少しきれいにし、あなたはまた、PHPファイルを提供している場合を除き、PHPの一部を削除しました。

upstream adshackers { 
      server localhost:1336; 
} 

server { 
     listen 80 default_server; 
     listen [::]:80 default_server; 

     root /var/www/html; 

     server_name adshackers.com; 

     location/{ 
      proxy_pass http://adshackers; 
      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection 'upgrade'; 
      proxy_set_header Host $host; 
      proxy_cache_bypass $http_upgrade; 
     } 
} 

アップストリーム部分には、アプリへのプロキシリクエストの情報が含まれている必要があります。私はあなたのアプリがあなたのnginxが実行されているのと同じマシン上にホストされていると仮定しており、あなたの例が示すようにlocalhost:1336を聞いています。

この場合、http要求がadshackers.comに来ると(DNSエントリが正しい場合)、nginxは要求をlocalhost:1336に転送します。

+1

は、テールスラッシュとPHP部分を削除し、うわべ...それは働いています。 –

関連する問題