末尾带有圆点的请求给出了错误的请求400

时间:2019-08-16 09:02:05

标签: django nginx uwsgi nginx-location

这是我访问的配置

https://www.example.com.

末尾的点不起作用

# the upstream component nginx needs to connect to
upstream django {
    server unix:///tmp/example.sock; # for a file socket
}

# Redirect
server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/example.key;
    rewrite ^(.*) $scheme://www.example.com$1 permanent;
}


# SSL Request
server {
    listen 443;
    server_name www.example.com;
    root /var/www/example;
    charset utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    ssl on;
    ssl_certificate /etc/nginx/ssl/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/example.key;
    ssl_protocols TLSv1.2 TLSv1.1;

    # Django media
    location /uploads  {
        alias /var/www/example/uploads;  # your Django project's media files - amend as required
        expires 7d;
    }

    location /static {
        alias /var/www/example/static; # your Django project's static files - amend as required
        expires 7d;
    }

    location /favicon.ico {
        alias /var/www/example/static/img/favicon.ico; # your Django project's static files - amend as required
    }

    location /robots.txt {
        alias /var/www/example/robots.txt; # robots.txt
    }

    location /ntat {
        uwsgi_pass  django;
        include     uwsgi_params;
    }

    location / {
        rewrite ^(.*) http//www.example.com$1;
    }
}

# Normal Request
server {
    # the port your site will be served on
    listen 80;
    # the domain name it will serve for
    server_name www.example.com
    charset utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /ntat {
        rewrite ^(.*) https://www.example.com$1;
   }

   # Django media
    location /uploads  {
        alias /var/www/example/uploads;  # your Django project's media files - amend as required
        expires 7d;
    }
    location /ntat {
        rewrite ^(.*) https://www.example.com$1;
   }

   # Django media
    location /uploads  {
        alias /var/www/exam/uploads;  # your Django project's media files - amend as required
        expires 7d;
    }

    location /static {
        alias /var/www/example/static; # your Django project's static files - amend as required
        expires 7d;
    }

    location /favicon.ico {
        alias /var/www/example/static/img/favicon.ico; # your Django project's static files - amend as required
    }

    location /robots.txt {
        alias /var/www/example/robots.txt; # robots.txt
    }

    location /timepass  {
        alias /var/www/timepass;  # Snake Game
    }

    # Finally, send all non-media requests to the Django server.
    location / {
       rewrite ^(.*) https://www.example.com$1;
       uwsgi_pass  django;
       include     uwsgi_params;
       uwsgi_read_timeout 180;
    }
}

1 个答案:

答案 0 :(得分:0)

  • 确保根据需要default_server
  • 请勿在{{1​​}}处使用rewrite
  • 始终指定return以确保server_name之间没有不同的优先级
  • 注意server(缺少http//www.example.com$1;

:www.example.com.different server name for NGINX,但是您没有www.example.com专门监听点分域,因此最好使用默认服务器标记server块,以确保正确匹配。

server