标签: django

如何让 apache 处理 .well-known/acme-challenge 并仍然将 / 传递给 wsgi

为了支持自动 LetsEncrypt 证书续订,certbot 使用--apache处理程序。

例如

certbot renew --apache
Run Code Online (Sandbox Code Playgroud)

该处理程序在 Apache 服务器上为*/.well-known/acme-challenge/安装一个临时 VirtualHost ,以验证续订。

问题是,如果现有虚拟服务器使用安装在 http 服务器根目录上的 HTTPS 和 Django over WSGI,则此机制不起作用。

临时 VirtualHost 无法捕获 URL,因此 Django 尝试为请求提供服务(但失败),因为该 URL 不在其 URL 列表中。

django wsgi lets-encrypt apache2

7
推荐指数
1
解决办法
7226
查看次数

是否可以在启动时自动运行 celery?

我有基于 django 和 celery 的 python 服务器。每次计算机重新启动时,apache2 都会启动,因此我的服务器正在运行,但我必须手动重新启动 celery(转到我的项目目录并执行“python manage.py celeryd”)。生产的正确解决方案是什么?我的意思是,是否有可能将 celery 作为守护进程启动?

在这里http://github.com/ask/celery/tree/master/contrib/debian/init.d/我发现了两个脚本,它们看起来应该在 /etc/init.d/ 中,就像启动 apache2 的 apache2 脚本一样。但是我把它们放在 /etc/init.d/ 中,我看没有任何变化。

linux django celery

6
推荐指数
1
解决办法
4225
查看次数

开发、测试、分期和生产模型

我正在开发一个带有 Postgres 数据库的由 Mill django 驱动的网站。我在本地开发并拥有 3 个 VPS 服务器用于测试、登台和生产。每个 VPS 运行自己的 Linux / Apache / Python / Postgres 堆栈,以及自己的数据库。

我开始发现,随着使用 git 的持续部署,暂存实际上变得多余(从暂存转移到生产需要交换 IP 地址,这需要重新启动 VPS)。

我能预见到临时有用的唯一时间是需要进行复杂的数据库迁移时,即使这样,由于临时和生产上的 Postgres 数据库没有镜像,可能会出现丢失迁移之间输入的数据的问题。

我的问题是我应该在登台和生产之间镜像 Postgres 吗?(如果是这样,怎么做?)我做得对吗?我在任何地方都找不到关于 Web 应用程序部署最佳实践的大量文档。

postgresql linux deployment django

6
推荐指数
1
解决办法
1471
查看次数

在 Ubuntu 上安装 XSendFile 的问题

我安装了 apache dev 头文件:

sudo apt-get install apache2-prefork-dev
Run Code Online (Sandbox Code Playgroud)

下载并编译模块,如下所述:http : //tn123.ath.cx/mod_xsendfile/

将以下行添加到 /etc/apache2/mods-available/xsendfile.load:

LoadModule xsendfile_module /usr/lib/apache2/modules/mod_xsendfile.so
Run Code Online (Sandbox Code Playgroud)

将此添加到我的 VirtualHost:

<VirtualHost *:80>
    XSendFile on
    XSendFilePath /path/to/protected/files/
Run Code Online (Sandbox Code Playgroud)

通过执行以下操作启用模块:

sudo a2enmod xsendfile
Run Code Online (Sandbox Code Playgroud)

然后我重新启动了Apache。然后这段代码仍然只是为我提供了一个 0 字节的空文件:

file_path = '/path/to/protected/files/some_file.zip'
file_name = 'some_file.zip'
response = HttpResponse('', mimetype='application/zip')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(file_path)
return response
Run Code Online (Sandbox Code Playgroud)

Apache 错误日志中也没有与 XSendFile 相关的内容。我究竟做错了什么?

ubuntu django apache-2.2

6
推荐指数
1
解决办法
2143
查看次数

为子域问题设置 CNAME

我会为此设置:

  • 用户去 test.example_site1.org
  • test.example_org1.org 它是 test.example_org2.org 的 CNAME
  • 用户将看到 test.example_org2.org 的页面

在 example_org2.org 服务器上,我使用 nginx 并且我有 3 个 django 项目。

test.example_org2.org 展示了第三个 django 项目。http://example_org2.org展示了第一个 django 项目。

问题是我在 example_org1.org 上设置了一个 CNAME 以将 test.example_org1.org 指向 test.example_org2.org ,但是如果我尝试去http://test.example_org1.org我看到第一个django项目,其中一个配置到主域而不是子域。否则,如果我直接访问http://test.example_org2.org一切正常,我会看到正确的项目。

为什么会出现这个问题?

nginx django cname-record

6
推荐指数
2
解决办法
1万
查看次数

nginx+django 服务静态文件

我已经按照 django wiki ( https://code.djangoproject.com/wiki/DjangoAndNginx ) 中的 nginx 设置django 的说明进行了操作,并按如下方式进行了 nginx 设置(更改了一些名称以适应我的设置)。

    user  nginx nginx;

worker_processes  2;

error_log /var/log/nginx/error_log info;

events {
    worker_connections  1024;
    use epoll;
}

http {
    include     /etc/nginx/mime.types;
    default_type    application/octet-stream;

    log_format main
        '$remote_addr - $remote_user [$time_local] '
            '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';

    client_header_timeout   10m;
    client_body_timeout 10m;
    send_timeout        10m;

    connection_pool_size        256;
    client_header_buffer_size   1k;
    large_client_header_buffers 4 2k;
    request_pool_size       4k;

    gzip on;
    gzip_min_length 1100;
    gzip_buffers    4 8k;
    gzip_types  text/plain;

    output_buffers  1 32k;
    postpone_output 1460;

    sendfile    on;
    tcp_nopush …
Run Code Online (Sandbox Code Playgroud)

nginx django

6
推荐指数
1
解决办法
2万
查看次数

使用 supervisord 运行 django 自定义管理命令

我想使用 supervisord 为我的 Django 项目运行一些命令,但我不断收到以下错误:

主管.log:

2012-05-18 17:52:15,784 INFO spawnerr: can't find command 'source'
Run Code Online (Sandbox Code Playgroud)

如果我删除“源”命令,日志会显示相同的错误:can't find command 'python'.

supervisord.conf 摘录:

[program:django]
directory=/home/mf/projects/djangopj/
command=beanstalkd -l 127.0.0.1 -p 11300
command=source /home/mf/virtualenvs/env/bin/activate
command=python manage.py command1
command=python manage.py command2
user=mf
autostart=true
autorestart=true
Run Code Online (Sandbox Code Playgroud)

我尝试删除目录并将绝对路径添加到命令中,但我一直收到相同的错误。

我使用以下命令运行 supervisord:

supervisord -c supervisord.conf -l supervisor.log
Run Code Online (Sandbox Code Playgroud)

django supervisord

6
推荐指数
1
解决办法
4179
查看次数

如何在私有 IP 上实施 SSL?

我正在开发一个网络管理产品。我们将产品作为虚拟机交付给客户,他们将其安装在网络中的虚拟机管理程序上。这些虚拟机在客户网络中获得静态私有 IP 地址。他们监视客户的设备,并运行显示网络状态的 (Apache/Django) Web 服务器。客户通过私有 IP 访问该站点,而我们直接使用 TeamViewer(在发货前安装)访问虚拟机,因此不涉及公共 IP 或域名。我们非常希望在我们的虚拟机上提供 SSL 证书,以便客户不再看到我们的网站不安全的通知(当然,这样我们的网站就不再不安全)。最好,客户不必添加对新 CA 的信任或向其浏览器添加安全例外。

最有效且最具成本效益的方法是什么?我尝试过LetsEncrypt,但他们只支持域名证书,不支持IP。

ssl django

6
推荐指数
2
解决办法
2万
查看次数

自定义标头的 nginx 变量是什么?

客户端正在向我的 Nginx 反向代理发送自定义 HTTP 标头X-ABC-LOGIN-NAME。为了确保它确实到达,安装了 PHP 服务器 (fastcgi),并且此标头确实显示在phpinfo()“PHP 变量”部分中(带有值)。

我使用 Gunicorn 服务器操作 Django 后端,并在 Django 代码中将所有标头打印到控制台。当我为 /etc/nginx/sites-enabled/default 中的 分配静态值时X-ABC-LOGIN-NAME,该值到达后端。在 nginxdefault文件中,如下所示:

server {
    listen      443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    # include snippets/self-signed.conf;
    # include snippets/ssl-params.conf;
    # server_name   localhost;
    server_name dev_server;

    underscores_in_headers on;

    location / {
    
        proxy_pass http://localhost:8000;
        proxy_pass_request_headers on;
    
        proxy_http_version 1.1;
    
        proxy_set_header Upgrade $http_upgrade;
    
        proxy_set_header X-ABC-LOGIN-NAME "static_name"; # <-- "static_name" arrives …
Run Code Online (Sandbox Code Playgroud)

nginx reverse-proxy django

6
推荐指数
0
解决办法
2万
查看次数

使用 Nginx 阻止未发送至我的域的连接

我正在 AWS elastic beanstalk 上运行 django 应用程序,并且收到尝试扫描漏洞的机器人发送的垃圾邮件。它会导致大量错误,例如:

(其中 xx.xxx.xx.xx 是我的 ec2 实例的 IP 地址。)

DisallowedHost at //www/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php
Invalid HTTP_HOST header: 'xx.xxx.xx.xx'. You may need to add 'xx.xxx.xxx.xx' to ALLOWED_HOSTS.
Run Code Online (Sandbox Code Playgroud)

我的合法用户只能使用域名访问该网站。我一直在尝试找出如何修改我的 nginx 配置以阻止所有未寻址到 *.mydomain.com 或 mydomain.com 的连接。

我根据需要动态添加和删除子域,因此我为子域使用通配符。

AWS Elastic beanstalk 为我生成以下默认配置文件:

/etc/nginx/nginx.conf

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    32788;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" …
Run Code Online (Sandbox Code Playgroud)

nginx django elastic-beanstalk

6
推荐指数
1
解决办法
6985
查看次数