Vultr ・Choose Server:Cloud Compute ・Server Type:Ubuntu 18.04 ☆requirements.txt Django~=2.2.10 django-allauth~=0.43.0 django-widget-tweaks~=1.4.8 Pillow~=6.2.1 django-environ~=0.4.5 gunicorn~=20.0.4 pygame ==2.0.0 ``` **☆config/settings.py** import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'widget_tweaks', 'app', 'accounts', 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'drug', 'vital', ] 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 = 'config.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], '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', ], }, }, ] WSGI_APPLICATION = 'config.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } 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', }, ] LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True STATIC_URL = '/static/' MEDIA_URL = '/media/' SITE_ID = 1 LOGIN_REDIRECT_URL = '/' ACCOUNT_LOGOUT_REDIRECT_URL = '/' ACCOUNT_EMAIL_VERIFICATION = 'none' AUTH_USER_MODEL = 'accounts.CustomUser' ACCOUNT_AUTHENTICATION_METHOD = 'email' ACCOUNT_USER_MODEL_USERNAME_FIELD = None ACCOUNT_EMAIL_REQUIRED = True ACCOUNT_USERNAME_REQUIRED = False # デプロイ設定 DEBUG = False try: from .local_settings import * except ImportError: pass # ローカル用設定 if DEBUG: ALLOWED_HOSTS = ['*'] EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') if not DEBUG: import environ env = environ.Env() env.read_env(os.path.join(BASE_DIR,'.env')) SECRET_KEY = env('SECRET_KEY') ALLOWED_HOSTS = env.list('ALLOWED_HOSTS') EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.mail.me.com' EMAIL_PORT = 587 EMAIL_HOST_USER = env('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD') EMAIL_USE_TLS = True STATIC_ROOT = '/usr/share/nginx/html/static' MEDIA_ROOT = '/usr/share/nginx/html/media' **☆local_settings.py** DEBUG = True SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ``` **☆config/urls.py** from django.contrib import admin from django.urls import path,include from django.conf.urls.static import static from django.conf import settings from django.views.generic import TemplateView from django.views.decorators.cache import cache_control urlpatterns = [ path('admin/', admin.site.urls), path('',include('app.urls')), path('accounts/',include('accounts.urls')), path('drug/',include('drug.urls')), path('vital/',include('vital.urls')), path('sw.js', (TemplateView.as_view(template_name="sw.js", content_type='application/javascript', )), name='sw.js'), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT) .env SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ALLOWED_HOSTS=127.0.0.1,サーバーIP EMAIL_HOST_USER=xxxxxxxxxxxx EMAIL_HOST_PASSWORD=xxxxxxxxxxxxxxxxxxxxx **☆/etc/nginx/sites-available/default** server { listen 80; server_name サーバーIP; location /static { alias /usr/share/nginx/html/static; } location /media { alias /usr/share/nginx/html/media; } location / { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; } } --------------------------------------------------------------- **☆/etc/systemd/system/vget.service** [Unit] Description=gunicorn After=network.target [Service] WorkingDirectory=/home/goro/src/vget_plus ExecStart=/home/goro/src/vget_plus/ven/bin/gunicorn --bind 127.0.0.1:8000 config.wsgi:application [Install] WantedBy=multi-user.target ``` sudo nginx -t sudo systemctl restart nginx ●python3 manage.py runserver 0.0.0.0:8000 ⇦表示できます。ブラウザでVultrのIPアドレス⇦表示できない ●gunicorn --bind 127.0.0.1:8000 config.wsgi:application ⇦表示できます。ブラウザでVultrのIPアドレス⇦表示できない sudo systemctl start vget sudo systemctl restart vget ●ブラウザでVultrのIPアドレス⇦まったく表示できない? ```
あなたの回答
tips
プレビュー