A fresh Django application is running on the Debian server, configured via gunicorn and nginx. After setup i tried to connect to it, but i can reach it only by server ip and www.mydomain.ru, but not by mydomain.ru. The only error i found is in nginx log:
2023/08/10 16:08:48 [error] 19252#19252: *9 connect() failed (111: Connection refused) while connecting to upstream, client: x.xx.xxx.xxx, server: mydomain.ru, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "xxx.xxx.xxx.xxx:80"
or sometimes host: "mydomain.ru"
my nginx configuration:
server {
listen 80;
server_name mydomain.ru;
access_log /var/log/nginx/example.log;
location /static/ {
root /home/alex/myproject;
expires 30d;
}
location /media/ {
root /home/alex/myproject;
expires 30d;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name www.mydomain.ru;
access_log /var/log/nginx/example.log;
location /static/ {
root /home/alex/myproject;
expires 30d;
}
location /media/ {
root /home/alex/myproject;
expires 30d;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
my gunicorn.conf
bind = '127.0.0.1:8000'
workers = 2
user = 'alex'
timeout = 120
mydomain.ru is in django settings ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS, but anyway, when i python3 manage.py runserver
django shows some activity only accessing it by server ip and www.
when i stop project with supervisor there are no other servers in netstat -tpln
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 324/zabbix_agentd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20083/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 358/sshd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 17127/postgres
tcp6 0 0 :::22 :::* LISTEN 358/sshd
tcp6 0 0 ::1:5432 :::* LISTEN 17127/postgres
and it is there when i start project =)
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 20564/python3.9
I tried every options i found here, googled or got from chatgpt, but nothing helps me. Please, help me in this question, it will make me very happy. Thanks in advance!