Why is my Springboot deployment to EBS not working? - amazon-web-services

I am trying to deploy a small SpringBoot application to EBS. I think I have done everything right, including setting up an RDS database, but the deployment fails and I get an error with health degraded as : Following services are not running: application-web-1.
My variables are setup as follows
GRADLE_HOME
/usr/local/gradle
JAVA_HOME
/usr/lib/jvm/java
M2
/usr/local/apache-maven/bin
M2_HOME
/usr/local/apache-maven
SERVER_PORT
5000
SPRING_DATASOURCE_PASSWORD
***
SPRING_DATASOURCE_URL
jdbc:mysql://***.us-east-2.rds.amazonaws.com/ebdb
SPRING_DATASOURCE_USERNAME
***
SPRING_JPA_DATABASE_PLATFORM
org.hibernate.dialect.MySQL5Dialect
SPRING_JPA_HIBERNATE_DDL_AUTO
***
SPRING_PROFILES_ACTIVE
prod
Any advice on how to debug?
My logs below:
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2019/03/17 19:02:16 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 19:02:17 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 19:02:25 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /links/ HTTP/1.1", upstream: "http://127.0.0.1:5000/links/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 19:02:26 [error] 4817#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 82.29.139.73, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/links/"
2019/03/17 19:57:28 [error] 4817#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 178.73.215.171, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
2019/03/17 20:53:11 [error] 4817#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 104.152.52.21, server: , request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:5000/"
2019/03/17 20:57:57 [error] 4817#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 20:57:58 [error] 4817#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:06:08 [error] 29457#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:06:08 [error] 29457#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:15:47 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:15:48 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:15:54 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:15:54 [error] 30143#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:25:28 [error] 30981#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:25:28 [error] 30981#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:29:36 [error] 31520#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:29:36 [error] 31520#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"
2019/03/17 21:34:37 [error] 31520#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com"
2019/03/17 21:34:37 [error] 31520#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 151.229.68.196, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com", referrer: "http://ddemo-env.ipmbyempmi.us-east-2.elasticbeanstalk.com/"

Hey I'm not sure if this will work for you, but this is how I solved the
Following services are not running: application-web-1.
issue. I ssh'd onto my elastic beanstalk instance and cd'd to the /var/log directory. I noticed that there was a
web-1.error.log
log showing. I vi'd that log file and there was the exception that was causing the deployment to fail. A txt file that was nested inside a folder within my resources folder was not visible and the following exception was being thrown.
Caused by: java.io.FileNotFoundException: URL [jar:file:/var/app/current/application.jar!/BOOT-INF/classes!/vegetables/vegetables.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/var/app/current/application.jar!/BOOT-INF/classes!/vegetables/vegetables.txt
This occurred because I was using PathMatchingResourcePatternResolver to get the resources, then traversing the resources by filename, and directly trying to access the file by using resource.getFile(). Instead of getting the data by the file. I used
byte[] dataArr = FileCopyUtils.copyToByteArray(resource.getInputStream());
and that allowed me to use the data in the byte array the same way I used it by accessing the file directly. I hope this helps.

Related

intermittent 502 Bad Gateway nginx/1.18.0 (Ubuntu)

My django app has ben running for about 3 months now.
I intermittently get a 502 Bad Gateway error message on any page,
I will even get this error the Django admin page, so I don't think its my code. Most of the time the page loads fine, or if I just reload it will load.
can someone help me understand where I'm making a mistake
The output from sudo tail -20 /var/log/nginx/error.log yields:
2022/03/29 16:12:56 [error] 720#720: *8182 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /backyard/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/backyard/", host: "104.131.165.99", referrer: "http://104.131.165.99/backyard/"
2022/03/29 16:19:44 [error] 720#720: *8188 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 16:26:29 [error] 720#720: *8194 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 16:36:30 [error] 720#720: *8205 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 16:42:58 [error] 720#720: *8209 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /backyard/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/backyard/", host: "104.131.165.99", referrer: "http://104.131.165.99/backyard/"
2022/03/29 16:49:45 [error] 720#720: *8221 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:09:45 [error] 720#720: *8244 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:12:57 [error] 720#720: *8251 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /backyard/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/backyard/", host: "104.131.165.99", referrer: "http://104.131.165.99/backyard/"
2022/03/29 17:16:54 [error] 720#720: *8255 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:23:04 [error] 720#720: *8261 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:29:44 [error] 720#720: *8265 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:33:10 [error] 720#720: *8269 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:46:25 [error] 720#720: *8282 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 17:49:47 [error] 720#720: *8284 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 18:40:19 [error] 720#720: *8303 upstream prematurely closed connection while reading response header from upstream, client: 73.178.103.149, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99"
2022/03/29 18:44:53 [error] 720#720: *8310 upstream prematurely closed connection while reading response header from upstream, client: 73.178.103.149, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 18:50:50 [error] 720#720: *8320 upstream prematurely closed connection while reading response header from upstream, client: 73.178.103.149, server: _, request: "GET /admin/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/admin/", host: "104.131.165.99"
2022/03/29 18:51:19 [error] 720#720: *8319 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 73.178.103.149, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 18:52:56 [error] 720#720: *8324 upstream prematurely closed connection while reading response header from upstream, client: 73.178.103.149, server: _, request: "GET /garage/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/garage/", host: "104.131.165.99", referrer: "http://104.131.165.99/garage/"
2022/03/29 18:52:56 [error] 720#720: *8327 upstream prematurely closed connection while reading response header from upstream, client: 165.225.38.84, server: _, request: "GET /backyard/ HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/backyard/", host: "104.131.165.99", referrer: "http://104.131.165.99/backyard/"

502 Bad Gateway nginx/1.20.0 Error when Deploying Django app using AWS Elastic Beanstalk

I was following closely following AWS's documentation on how to deploy Django apps using Elastic Beanstalk until I received a 502 Bad Gateway nginx/1.20.0 Error when opening my app. From there, I followed a couple of solutions offered by users that suffered similar problems. Specifically, I added a Procfile and went about editing how my django.config file was set up. However, the error still remains and I would like some guidance on how to tackle this problem. Below are the relevant logs and files:
eb-engine.log
django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: djangoproject.wsgi:application
Procfile
web: gunicorn --bind :8000 --workers 3 --threads 2 djangoproject.wsgi:application
settings.py
"""
Django settings for djangoproject project.
Generated by 'django-admin startproject' using Django 3.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'thesecuritykey'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['localhost','127.0.0.1','djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'store.apps.StoreConfig',
'basket.apps.BasketConfig',
'account.apps.AccountConfig',
'orders.apps.OrdersConfig',
'checkout.apps.CheckoutConfig',
'mptt',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'djangoproject.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'store.context_processors.categories',
'basket.context_processor.basket'
],
},
},
]
WSGI_APPLICATION = 'djangoproject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static")
]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
requirements.txt
nginx error logs
2021/07/26 03:24:55 [error] 6904#6904: *119 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 03:42:04 [error] 6904#6904: *367 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 03:51:27 [error] 6904#6904: *503 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.237.64.108"
2021/07/26 03:53:58 [error] 6904#6904: *537 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.237.64.108"
2021/07/26 04:00:42 [error] 6904#6904: *633 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 04:07:37 [error] 6904#6904: *728 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 04:08:32 [error] 6904#6904: *728 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /.env HTTP/1.1", upstream: "http://127.0.0.1:8000/.env", host: "52.38.207.124"
2021/07/26 04:08:32 [error] 6904#6904: *728 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "POST / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 04:35:42 [error] 6904#6904: *1140 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /config/getuser?index=0 HTTP/1.1", upstream: "http://127.0.0.1:8000/config/getuser?index=0", host: "52.38.207.124"
2021/07/26 04:38:14 [error] 6904#6904: *1179 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.237.64.108"
2021/07/26 04:50:45 [error] 6904#6904: *1360 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 04:56:51 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 04:56:51 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /.DS_Store HTTP/1.1", upstream: "http://127.0.0.1:8000/.DS_Store", host: "52.38.207.124"
2021/07/26 04:56:52 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /nginx.conf HTTP/1.1", upstream: "http://127.0.0.1:8000/nginx.conf", host: "52.38.207.124"
2021/07/26 04:56:52 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /status HTTP/1.1", upstream: "http://127.0.0.1:8000/status", host: "52.38.207.124"
2021/07/26 04:56:52 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /status%3E%3Cscript%3Ealert(31337)%3C%2Fscript%3E HTTP/1.1", upstream: "http://127.0.0.1:8000/status%3E%3Cscript%3Ealert(31337)%3C%2Fscript%3E", host: "52.38.207.124"
2021/07/26 04:56:53 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /v2/_catalog HTTP/1.1", upstream: "http://127.0.0.1:8000/v2/_catalog", host: "52.38.207.124"
2021/07/26 04:56:53 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /server-status HTTP/1.1", upstream: "http://127.0.0.1:8000/server-status", host: "52.38.207.124"
2021/07/26 04:56:53 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /.env HTTP/1.1", upstream: "http://127.0.0.1:8000/.env", host: "52.38.207.124"
2021/07/26 04:56:54 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /.git/config HTTP/1.1", upstream: "http://127.0.0.1:8000/.git/config", host: "52.38.207.124"
2021/07/26 04:56:54 [error] 6904#6904: *1449 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /idx_config/ HTTP/1.1", upstream: "http://127.0.0.1:8000/idx_config/", host: "52.38.207.124"
2021/07/26 05:00:06 [error] 6904#6904: *1508 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.237.64.108"
2021/07/26 05:01:21 [error] 6904#6904: *1539 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /config/getuser?index=0 HTTP/1.1", upstream: "http://127.0.0.1:8000/config/getuser?index=0", host: "44.237.64.108"
2021/07/26 05:11:53 [error] 6904#6904: *1679 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.38.207.124"
2021/07/26 05:12:31 [error] 6904#6904: *1701 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "44.237.64.108"
2021/07/26 05:13:59 [error] 6904#6904: *1722 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com"
2021/07/26 05:14:00 [error] 6904#6904: *1722 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com", referrer: "http://djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com/"
2021/07/26 05:18:06 [error] 6904#6904: *1792 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "POST /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php HTTP/1.1", upstream: "http://127.0.0.1:8000/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php", host: "44.237.64.108"
2021/07/26 05:18:06 [error] 6904#6904: *1792 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php HTTP/1.1", upstream: "http://127.0.0.1:8000/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php", host: "44.237.64.108"
2021/07/26 05:18:06 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "POST /api/jsonws/invoke HTTP/1.1", upstream: "http://127.0.0.1:8000/api/jsonws/invoke", host: "44.237.64.108"
2021/07/26 05:18:07 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /?a=fetch&content=<php>die(#md5(HelloThinkCMF))</php> HTTP/1.1", upstream: "http://127.0.0.1:8000/?a=fetch&content=<php>die(#md5(HelloThinkCMF))</php>", host: "44.237.64.108"
2021/07/26 05:18:07 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /solr/admin/info/system?wt=json HTTP/1.1", upstream: "http://127.0.0.1:8000/solr/admin/info/system?wt=json", host: "44.237.64.108"
2021/07/26 05:18:07 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /index.php?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=md5&vars[1][]=HelloThinkPHP21 HTTP/1.1", upstream: "http://127.0.0.1:8000/index.php?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=md5&vars[1][]=HelloThinkPHP21", host: "44.237.64.108"
2021/07/26 05:18:08 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /?XDEBUG_SESSION_START=phpstorm HTTP/1.1", upstream: "http://127.0.0.1:8000/?XDEBUG_SESSION_START=phpstorm", host: "44.237.64.108"
2021/07/26 05:18:08 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /wp-content/plugins/wp-file-manager/readme.txt HTTP/1.1", upstream: "http://127.0.0.1:8000/wp-content/plugins/wp-file-manager/readme.txt", host: "44.237.64.108"
2021/07/26 05:18:08 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /console/ HTTP/1.1", upstream: "http://127.0.0.1:8000/console/", host: "44.237.64.108"
2021/07/26 05:18:09 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "POST /Autodiscover/Autodiscover.xml HTTP/1.1", upstream: "http://127.0.0.1:8000/Autodiscover/Autodiscover.xml", host: "44.237.64.108"
2021/07/26 05:18:09 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /_ignition/execute-solution HTTP/1.1", upstream: "http://127.0.0.1:8000/_ignition/execute-solution", host: "44.237.64.108"
2021/07/26 05:18:42 [error] 6904#6904: *1802 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.45.215, server: , request: "GET /manager/html HTTP/1.1", upstream: "http://127.0.0.1:8000/manager/html", host: "44.237.64.108"
2021/07/26 05:22:50 [error] 8765#8765: *44 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com"
2021/07/26 05:22:51 [error] 8765#8765: *44 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com", referrer: "http://djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com/"
2021/07/26 05:24:18 [error] 8765#8765: *68 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com"
2021/07/26 05:24:18 [error] 8765#8765: *68 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com", referrer: "http://djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com/"
2021/07/26 05:37:38 [error] 9377#9377: *72 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com"
2021/07/26 05:37:39 [error] 9377#9377: *72 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.15.153, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com", referrer: "http://djangoproject.eba-fuipjhfa.us-west-2.elasticbeanstalk.com/"
From the looks of it, the deployment seems successful. However, based on a handful of other posts like this, the nginx logs seem to show there may have been something wrong with getting gunicorn to work as the web server gateway interface. Any advice on how to solve this problem?
my deployment is still not good for production as I still have to provision manually from aws console the postgres database and change the SG inbound rules for the database.
so far this is what I came up with.
this is my diango.config file inside .ebextensions/ :
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "projectname.settings"
PYTHONPATH: "/var/app/current:$PYTHONPATH"
AWS_STORAGE_BUCKET_NAME: "nameofbucket"
AWS_S3_REGION_NAME: "yourregion"
RDS_USERNAME: "dbusername"
RDS_PASSWORD: "dbpassword"
RDS_PORT: 5432
aws:elasticbeanstalk:container:python:
WSGIPath: "projectname.wsgi:application"
NumProcesses: 3
NumThreads: 20
aws:elasticbeanstalk:environment:process:default:
HealthCheckPath: "/about"
MatcherHTTPCode: "200-499"
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
/media: media
container_commands:
01_makemigrations:
command: "source /var/app/venv/*/bin/activate && python3 manage.py makemigrations --noinput"
leader_only: true
02_migrate:
command: "source /var/app/venv/*/bin/activate && python3 manage.py migrate --noinput"
leader_only: true
03_createsu:
command: "source /var/app/venv/*/bin/activate && python3 manage.py createsu"
04_collectstatic:
command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput"
leader_only: true
this will create an enviroment that has not a database, I then provision from the console a postgres database.
I then run from terminal a script to set enviromental variable inside elastic beanstalk:
#!/bin/bash
eb setenv \
AWS_ACCESS_KEY_ID='' \
AWS_SECRET_ACCESS_KEY='' \
RDS_DB_NAME='' \
RDS_HOSTNAME=''
inside my setting.py file I pass something like this:
from decouple import config
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "static"
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"
try:
from .local_settings import *
AWS_ACCESS_KEY_ID = config("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = config("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = config("AWS_STORAGE_BUCKET_NAME")
AWS_S3_REGION_NAME = config("AWS_S3_REGION_NAME")
except ImportError:
print("no local file found")
## Django storages - use this for production
STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
print("no local file found you are in production")
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ["RDS_DB_NAME"],
"USER": os.environ["RDS_USERNAME"],
"PASSWORD": os.environ["RDS_PASSWORD"],
"HOST": os.environ["RDS_HOSTNAME"],
"PORT": os.environ["RDS_PORT"],
}
}
AWS_ACCESS_KEY_ID = config("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = config("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = config("AWS_STORAGE_BUCKET_NAME")
AWS_S3_REGION_NAME = config("AWS_S3_REGION_NAME")
this makes my project up and running on Elastic Beanstalk. as I said it is still not fully automatic as the part where I provision the database inside the config file does not work. Hope it is useful.
It seems like port 80 is important for AWS Elastic Beanstalk running a Docker environment with nginx. Make sure you EXPOSE 80 and EXPOSE 8000 in your Dockerfile. I was using docker-compose too, so I had to add ports: - 80:8000 to my docker-compose.yml.

Error 502 with conflicting server name and (2: No such file or directory)

Mywebsite.co.uk displays a 502 Error. Running sudo tail -F /var/log/nginx/error.log outputs:
2020/10/22 09:42:13 [warn] 200096#200096: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:13 [warn] 200107#200107: conflicting server name "mywebsite.co.uk" on 0.0.0.0:80, ignored
2020/10/22 09:42:29 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:42:50 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:42:51 [crit] 200110#200110: *4 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
2020/10/22 09:43:00 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:43:24 [error] 200110#200110: *1 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 09:57:01 [crit] 200110#200110: *10 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 103.42.252.150, server: _, request: "GET / HTTP/1.0", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx:80"
2020/10/22 10:07:00 [error] 200110#200110: *12 open() "/home/user/mywebsite-app/static/admin/css/fonts.css" failed (2: No such file or directory), client: 37.70.203.239, server: mywebsite.co.uk, request: "GET /static/admin/css/fonts.css HTTP/1.1", host: "mywebsite.co.uk", referrer: "http://mywebsite.co.uk/"
2020/10/22 10:07:28 [crit] 200110#200110: *15 connect() to unix:/home/django/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: 37.70.203.239, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/", host: "xxx.xx.xxx.xxx"
I suppose it might have somethint to do with gunicorn.socket being in /etc/systemd/system/gunicorn.socket and not at unix:/home/django/gunicorn.socket? Where do I need to change this? What else might be the problem?
My gunicorn.socket:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=user
Group=user
EnvironmentFile=/home/user/mywebsite-app/env
WorkingDirectory=/home/user/mywebsite-app
ExecStart=/home/user/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
mywebsite-app.wsgi:application
[Install]
WantedBy=multi-user.target
use unix:/run/gunicorn.sock in upstream or proxy_pass not your unix:/home/django/gunicorn.socket

AWS elasticbeanstalk with django isn't Working

]
I've never used an AWS Beanstalk before, and I get this error, and when I actually get to the address, the "502 badgateway" error is executed how can I solve this problem?(I'm using django)
Edit
I also downloaded the log and those are the errors
eb_engine.log
2020/07/13 02:49:45.963964 [ERROR] /usr/bin/id: healthd: no such user
2020/07/13 02:49:46.338947 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/healthd.service to /etc/systemd/system/healthd.service.
2020/07/13 02:49:46.746061 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/cfn-hup.service to
/etc/systemd/system/cfn-hup.service.
2020/07/13 02:50:26.754823 [ERROR] Creating a Pipfile for this project…
Requirements file provided! Importing into Pipfile…
2020/07/13 02:50:28.038589 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/eb-app.target to /etc/systemd/system/eb-app.target.
2020/07/13 02:50:28.121446 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/web.service to /etc/systemd/system/web.service.
2020/07/13 02:50:28.171612 [ERROR] nginx: the configuration file /var/proxy/staging/nginx/nginx.conf syntax is ok
nginx error
2020/07/13 03:00:43 [error] 3758#0: *140 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "52.79.129.169"
2020/07/13 03:02:41 [error] 3758#0: *162 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.10.51, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "13.209.157.1"
2020/07/13 03:15:07 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:08 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
2020/07/13 03:15:09 [error] 3758#0: *347 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.46.96, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "www.sewontax.com"
daemon
error (Invalid timestamp): {:id=>"0", :namespace=>"application", :timestamp=>1594609370, :data=>"{\"duration\":10,\"latency_histogram\":[[0.0,1]],\"http_counters\":{\"status_502\":1,\"request_count\":1}}"}

nginx + gunicorn 502 bad gateway

I'm trying to deploy a django project on VPS server via nginx and gunicorn, but I got an nginx error '502 bad gateway' when I try to open my page rollservice-rostov.ru
Something is wrong with my Nginx configuration, but I can't figure out what it is.
/etc/nginx/sites-enabled/rollservice.conf:
upstream rollservice-rostov.ru {
server 127.0.0.1:8010 fail_timeout=0;
}
server {
listen 80;
server_name www.rollservice-rostov.ru;
rewrite ^/(.*) http://rollservice-rostov.ru/$1 permanent;
client_max_body_size 4G;
access_log /home/django/logs/rollservice/nginx.access.log;
error_log /home/django/logs/rollservice/nginx.error.log;
location /static/ {
alias /home/django/projects/rollservice/static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://rollservice-rostov.ru;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/django/projects/rollservice/templates/;
}
}
/etc/supervisor/conf.d/rollservice.conf:
[program:rollservice]
command=/home/django/projects/rollservice/run/run.sh
directory=/home/django/projects/rollservice
user=django
autostart=true
autorestart=true
stderr_logfile=/home/django/logs/rollservice/gunicorn_errors.log
stdout_logfile=/home/django/logs/rollservice/gunicorn_access.log
/home/django/projects/rollservice/run/run.sh:
#!/bin/bash
NAME="rollservice"
SRCDIR=rollservice
HOMEDIR=/home/django
PROJECTDIR=${HOMEDIR}/projects/${NAME}
VIRTUALENV=${HOMEDIR}/.envs/${NAME}
SOCKFILE=${HOMEDIR}/tmp/${NAME}.sock
USER=django
GROUP=django
NUM_WORKERS=3
DJANGO_SETTINGS=rollservice.settings
DJANGO_WSGI_MODULE=rollservice.wsgi
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $PROJECTDIR
source ${VIRTUALENV}/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS
export PYTHONPATH=$PROJECTDIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec ${VIRTUALENV}/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=127.0.0.1:8010 \
--log-level=debug \
--log-file=$HOMEDIR/logs/
Although, my page opens successfully via
lynx http://127.0.0.1:8010
This is last error logs:
rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:18:34 [error] 11425#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:29:02 [error] 11423#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 67.148.203.206, server: rollservice-rostov.ru, request: "GET /ccs.php?input HTTP/1.0", upstream: "http://185.20.226.216:81/ccs.php?input", host: "rollservice-rostov.ru"
2014/10/12 23:29:02 [error] 11423#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 67.148.203.206, server: rollservice-rostov.ru, request: "GET /modules/404.php HTTP/1.0", upstream: "http://185.20.226.216:81/modules/404.php", host: "rollservice-rostov.ru"
2014/10/12 23:33:10 [error] 11905#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:33:12 [error] 11905#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 141.105.68.10, server: rollservice-rostov.ru, request: "GET /ccs.php?input HTTP/1.0", upstream: "http://185.20.226.216:81/ccs.php?input", host: "rollservice-rostov.ru"
[vps]rollservice> sudo tail /var/log/nginx/error.log
2014/10/12 23:13:27 [error] 11106#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:16:46 [error] 11295#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:18:34 [error] 11425#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:29:02 [error] 11423#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 67.148.203.206, server: rollservice-rostov.ru, request: "GET /ccs.php?input HTTP/1.0", upstream: "http://185.20.226.216:81/ccs.php?input", host: "rollservice-rostov.ru"
2014/10/12 23:29:02 [error] 11423#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 67.148.203.206, server: rollservice-rostov.ru, request: "GET /modules/404.php HTTP/1.0", upstream: "http://185.20.226.216:81/modules/404.php", host: "rollservice-rostov.ru"
2014/10/12 23:33:10 [error] 11905#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 185.20.226.216, server: rollservice-rostov.ru, request: "GET / HTTP/1.0", upstream: "http://185.20.226.216:81/", host: "rollservice-rostov.ru"
2014/10/12 23:33:12 [error] 11905#0: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 141.105.68.10, server: rollservice-rostov.ru, request: "GET /ccs.php?input HTTP/1.0", upstream: "http://185.20.226.216:81/ccs.php?input", host: "rollservice-rostov.ru"
2014/10/12 23:35:22 [error] 11905#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 93.72.37.129, server: rollservice-rostov.ru, request: "GET / HTTP/1.1", upstream: "http://185.20.226.216:81/", host: "185.20.226.216"
2014/10/12 23:35:22 [error] 11905#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 93.72.37.129, server: rollservice-rostov.ru, request: "GET /favicon.ico HTTP/1.1", upstream: "http://185.20.226.216:81/favicon.ico", host: "185.20.226.216"
2014/10/12 23:35:22 [error] 11905#0: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 93.72.37.129, server: rollservice-rostov.ru, request: "GET /favicon.ico HTTP/1.1", upstream: "http://185.20.226.216:81/favicon.ico", host: "185.20.226.216"
The problem looks to be with the proxy_pass is passing to a FQDN due to the naming of your up stream.
if (!-f $request_filename) {
proxy_pass http://rollservice-rostov.ru;
break;
}
It is passing it straight to that. Change the name of the upstream and you should be okay.
Joe
i think it's Django configuration related:
if you have set DEBUG to False , ALLOWED_HOSTS is used
To allow any domain name
ALLOWED_HOSTS = ['*',]
To allow only your domain name
ALLOWED_HOSTS = ['rollservice-rostov.ru',]
Config file settings.py may look :
...
DEBUG = False
ALLOWED_HOSTS = ['rollservice-rostov.ru',]
...
To include subdomains , add "." at start
ALLOWED_HOSTS = ['.rollservice-rostov.ru',]
Also , in Django 1.7 and more
ALLOWED_HOSTS = [
'.rollservice-rostov.ru', # Allow domain and subdomains
'.rollservice-rostov.ru.', # Also allow FQDN and subdomains
]
Check Django docs
https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts