Django и и Nginx не добавляют все доменные имена

У меня есть проект с Django, запущенный на машине Linux. Проект работал очень хорошо. но после того, как мы изменили доменное имя с "http://myservername:port/" на "https://myservername/projectname/", он больше не работает. Если я нажимаю на URL, я перенаправляюсь на "https://myservername/", но не на "https://myservername/projectname/", что дает мне ошибку 404. А если добавить вручную "projectname" в URL в браузере, то все работает нормально. Мои URL в Django выглядят следующим образом:

urlpatterns = [
    path('', include('pages.urls')),
    path('dashboards/', include('dashboards.urls')),
    path('django_plotly_dash/', include('django_plotly_dash.urls')),
    path('admin/', admin.site.urls),
]

# and pages url:
urlpatterns = [
    path('', views.index, name='index-pages'),
    # re_path(r'^culture-crawler/$', views.index, name='home'),
    # # path('culture-crawler/register/', views.register_page, name='register'),
    re_path(r'^login/$', views.login_page, name='login'),
    re_path(r'^logout/$', views.logout_user, name='logout'),
]

# and dashboards
urlpatterns = [
    path('dashboard/', views.dashboard, name='dashboard')
]

Файл Nginx:

upstream culture_crawler_app {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).

  server unix:/home/webapps/culturecrawler/run/gunicorn.sock fail_timeout=0;
}


server {

    listen 127.0.0.1:100;
    server_name hammbwdsc02;

    client_max_body_size 4G;

    access_log /home/webapps/culturecrawler/logs/nginx-access.log;
    error_log /home/webapps/culturecrawler/logs/nginx-error.log;

    location /static/ {
        alias   /home/webapps/culturecrawler/culture_crawler/static/;
    }

    location /media/ {
        alias   /home/webapps/culturecrawler/culture_crawler/media/;
    }

    location / {
        # an HTTP header important enough to have its own Wikipedia entry:
        #   http://en.wikipedia.org/wiki/X-Forwarded-For
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # enable this if and only if you use HTTPS, this helps Rack
        # set the proper protocol for doing redirects:
        # proxy_set_header X-Forwarded-Proto https;

        # pass the Host: header from the client right along so redirects
        # can be set properly within the Rack application
        proxy_set_header Host $http_host;

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        # for solving "upstream sent too big header" error
        proxy_buffering         on;
        proxy_buffer_size       128k;
        proxy_buffers           4 256k;
        proxy_busy_buffers_size 256k;

        # for solving timeout errors with too big files
        proxy_connect_timeout   300s;
        proxy_read_timeout      300s;

        # set "proxy_buffering off" *only* for Rainbows! when doing
        # Comet/long-poll stuff.  It's also safe to set if you're
 # using only serving fast clients with Unicorn + nginx.
        # Otherwise you _want_ nginx to buffer responses to slow
        # clients, really.
        # proxy_buffering off;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://culture_crawler_app;
            break;
        }
    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /404.html {
        root /home/webapps/culturecrawler/culture_crawler/templates/;
    }
}




Наконец-то гуникорн:


  GNU nano 2.9.3                                                                               venv/bin/gunicorn_start

#!/bin/bash
--env SCRIPT_NAME=/culture-crawler
NAME="culture-crawler"                                  # Name of the application
DJANGODIR=/home/webapps/culturecrawler/culture_crawler             # Django project directory
SOCKFILE=/home/webapps/culturecrawler/run/gunicorn.sock  # we will communicte using this unix socket
USER=webapps                                        # the user to run as
GROUP=webapps                                     # the group to run as
NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=culture_crawler.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=culture_crawler.wsgi                     # WSGI module name
TIMEOUT=1200

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source ../venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$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 ../venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --timeout $TIMEOUT \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-





Я понятия не имею, где я ошибаюсь. Есть предложения?

Вернуться на верх