我可以在访问我的IP地址时访问我的网站,但是当我访问我的域名时,我无法访问。
这是我的 nginx配置文件(我已更改了IP和域名以保护隐私):
server {
listen 80;
server_name my.ip.address example.com www.example.com;
location = /facivon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/tony/vp/vp/config/;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/tony/vp/vp/vp.sock;
}
}
这是我的制作settings.py文件:
from .base import *
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', '0.0.0.0', 'my.ip.address', 'example.com', '.example.com']
ROOT_URLCONF = "urls.production_urls"
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_SSL_DIRECT = True
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
X_FRAME_OPTIONS = 'DENY'
SECURE_HSTS_SECONDS = 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'vp',
'USER': 'vp',
'PASSWORD': os.environ["VP_DB_PASS"],
'HOST': 'localhost',
}
}
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL ='media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
是的,我的域名已连接到数字海洋。
可能导致错误请求的原因是什么?
提前致谢!
编辑:
出于某种原因,我有nginx的多个error.log。它可能与我修复此问题的许多尝试有关。您可以在下面找到相关的error.log:
2017/04/23 17:44:56 [alert] 17723#17723: *7 open socket #12 left in connection 4
2017/04/23 17:44:56 [alert] 17723#17723: *10 open socket #13 left in connection 6
2017/04/23 17:44:56 [alert] 17723#17723: *11 open socket #14 left in connection 7
2017/04/23 17:44:56 [alert] 17723#17723: *13 open socket #16 left in connection 9
2017/04/23 17:44:56 [alert] 17723#17723: *14 open socket #17 left in connection 10
2017/04/23 17:44:56 [alert] 17723#17723: *15 open socket #18 left in connection 11
2017/04/23 17:44:56 [alert] 17723#17723: aborting
2017/04/23 23:26:15 [emerg] 20136#20136: unknown directive "cd" in /etc/nginx/sites-enabled/vp:1
2017/04/23 23:27:12 [emerg] 20147#20147: unknown directive "cd" in /etc/nginx/sites-enabled/vp:1
2017/04/23 23:37:43 [alert] 20399#20399: *12 open socket #14 left in connection 7
2017/04/23 23:37:43 [alert] 20399#20399: *7 open socket #18 left in connection 9
2017/04/23 23:37:43 [alert] 20399#20399: aborting
/ etc / nginx / sites-enabled / vp:1中的行:unknown指令“cd”已修复。
在检查gunicorn的状态时,我得到以下信息:
sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2017-04-23 14:52:07 UTC; 19h ago
Main PID: 16044 (gunicorn)
Tasks: 4
Memory: 86.6M
CPU: 42.667s
CGroup: /system.slice/gunicorn.service
├─16044 /home/tony/vp/vpenv/bin/python3 /home/tony/vp/vpenv/bin/gunicorn --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application
├─16049 /home/tony/vp/vpenv/bin/python3 /home/tony/vp/vpenv/bin/gunicorn --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application
├─16050 /home/tony/vp/vpenv/bin/python3 /home/tony/vp/vpenv/bin/gunicorn --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application
└─16051 /home/tony/vp/vpenv/bin/python3 /home/tony/vp/vpenv/bin/gunicorn --workers 3 --bind unix:/home/tony/vp/vp/vp.sock vp.wsgi:application
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16044] [INFO] Starting gunicorn 19.7.1
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16044] [INFO] Listening at: unix:/home/tony/vp/vp/vp.sock (16044)
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16044] [INFO] Using worker: sync
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16049] [INFO] Booting worker with pid: 16049
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16050] [INFO] Booting worker with pid: 16050
Apr 23 14:52:07 vp-first gunicorn[16044]: [2017-04-23 14:52:07 +0000] [16051] [INFO] Booting worker with pid: 16051
Apr 23 15:27:51 vp-first systemd[1]: Started gunicorn daemon.
Apr 23 17:12:36 vp-first systemd[1]: Started gunicorn daemon.
Apr 23 17:31:37 vp-first systemd[1]: Started gunicorn daemon.
Apr 23 23:35:18 vp-first systemd[1]: Started gunicorn daemon.