2017-08-05 66 views
2

我在AWS彈性beanstalk上託管了我的spring引導應用程序,但是當我嘗試使用公共URL訪問它時,它給我502網關錯誤。 在日誌中,我可以看到以下錯誤: 2017/08/05 20:10:33 [錯誤] 22965#0:* 157連接()失敗(111:連接被拒絕)而 連接到上游,客戶端: XXX.68.241.XXX,服務器:,請求:「GET /swagger-ui.html HTTP/1.1」,上游:「http://127.0.0.1:5000/swagger-ui.html」,主機: 「XXXXXXXX-env.XXX.us-west-2.elasticbeanstalk.com 「無法訪問EBS上託管的彈簧啓動應用程序

user nginx; 
worker_processes auto; 
error_log /var/log/nginx/error.log; 
pid /var/run/nginx.pid; 

events { 
    worker_connections 1024; 
} 

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


    upstream tomcat_servers{ 
    ip_hash; 
    server 127.0.0.1:5000; 
    keepalive 256; 
    } 

    access_log /var/log/nginx/access.log main; 

    sendfile   on; 
    tcp_nopush   on; 
    tcp_nodelay   on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include    /etc/nginx/mime.types; 
    default_type  application/octet-stream; 


} 
+0

是端口上的安全組80打開?這是單個實例還是背後的負載平衡?在公共子網上? – strongjz

+1

@strongjz再次查看來自日誌的錯誤消息。與實例和安全組的連接很好。 –

+0

@strongjz是80在安全組中打開。 nginx正在向http://127.0.0.1:5000/swagger-ui.html上傳請求,但它仍然給502錯誤 –

回答

0

我會仔細檢查您的Spring啓動應用程序運行的端口。

By default, Spring Boot applications will listen on port 8080. Elastic Beanstalk assumes that the application will listen on port 5000. There are two ways to fix this discrepancy: change the port Elastic Beanstalk is configured to use, or change the port the Spring Boot application listens on. For this post, we will change the port the Spring Boot application listens on.

The easiest way to do this is to specify the SERVER_PORT environment variable in the Elastic Beanstalk environment and set the value to 5000. (The configuration property name is server.port, but Spring Boot allows you to specify a more environment variable-friendly name).

https://aws.amazon.com/blogs/devops/deploying-a-spring-boot-application-on-aws-using-aws-elastic-beanstalk/

Answered here as well

Help on how to update the port

+0

得到它的工作。謝謝:) –

+1

我沒有在EBS環境配置中添加端口號 –

相關問題