【问题标题】:Serving testpage while running django on nginx在 nginx 上运行 django 时提供测试页
【发布时间】:2017-09-25 12:15:50
【问题描述】:

我正在处理 https://serversforhackers.com/video/letsencrypt-for-free-easy-ssl-certificateshttps://certbot.eff.org/docs/intro.html ,试图向我的网站添加一个 ssl 证书(ubuntu 16.04 上的 nginx 上的 django 1.8)。我希望能够从我的服务器提供测试页面。我的 nginx 文档根目录位于 /var/www/html。

deploy@server:/var/www$ ll html/
total 40
drwxr-xr-x 3 root root  4096 Apr 26 21:17 ./
drwxr-xr-x 3 root root  4096 Apr 25 16:27 ../
drwxrwxrwx 2 root root  4096 Apr 27 11:16 .well-known/
-rw-r--r-- 1 root root 11321 Jun 21  2016 index.html
-rw-r--r-- 1 root root   612 Feb  6 16:43 index.nginx-debian.html
-rw-r--r-- 1 root root 11321 Apr 26 21:17 test.html

nginx 有 2 个配置文件。第一个是默认的,具有以下位置块:

    location ~ /.well-known {
            allow all;
    }
    location ~ /.well-known/acme-challenge/ {
            allow all;
    }

第二个是:

# configuration file /etc/nginx/sites-enabled/example:
server {
    #listen 80;
    listen 80  ;
    listen [::]:80  ;
    listen 443 ssl http2  ;
    listen [::]:443 ssl http2  ;


    server_name  example.org www.example.org;
    include snippets/ssl-example.org.conf;
    include snippets/ssl-params.conf;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/deploy/example3;
    }

    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:/run/uwsgi/example.sock;
    }

location ~* (?:^|/)\.  {
    allow all;
}

location ^~ /\.well-known {
            allow all;
    }

我希望能够通过以下方式提供测试页面:

http://example.com/test.html

相反,我得到了上面的屏幕截图。如何配置 nginx 或 django 以允许提供测试页面?

【问题讨论】:

  • 这与“允许所有”指令没有任何关系。其余的配置在哪里,特别是为 Django 服务的别名?
  • 我已经在上面添加了完整的文件。

标签: python django ubuntu nginx


【解决方案1】:

我认为问题不在于nginx配置,而在于urls.py配置。根据屏幕截图,您尚未配置与您尝试访问的 URL 匹配的 url 模式 r'^test.html$'

你可以在Django documentation找到更多关于配置url的信息。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-06-06
  • 1970-01-01
  • 2020-06-02
  • 2016-02-09
  • 2020-05-21
  • 1970-01-01
  • 2014-07-07
  • 2020-07-02
相关资源
最近更新 更多