【问题标题】:How do I receive subdomain wildcards on Apache2 using mod wsgi?如何使用 mod wsgi 在 Apache2 上接收子域通配符?
【发布时间】:2016-07-24 05:27:58
【问题描述】:

我正在使用 Django 1.8 开发应用程序,我正在尝试接收子域,然后根据子域呈现自定义主页。例如:example.com 是我公司的主页,用户注册为 conqueryyor.example.com,他们会得到一个名为“conqueryor.example.com”或任何他们想要的新主页。

听起来很简单,甚至还有我正在使用的 django 子域库。我当前的问题在于在本地设置 Apache2 和 mod WSGI,以便我可以在影响项目中的其他人之前在本地对其进行测试。我目前可以在我的 /etc/hosts 文件中使用以下 .conf 文件,其中包含 127.0.0.1 example.dev127.0.0.1 .example.dev 行。在我的浏览器中,我可以从 example.dev 访问我的应用程序,但是如果我尝试任何子域,我会收到“未找到服务器”页面。我也尝试使用 dnsmasq 并添加行 address=/.example.dev/127.0.0.1

当前环境: Ubuntu 15.10 Django 1.8.1 阿帕奇 2.4

<VirtualHost *:80>
ServerName example.dev

DocumentRoot /home/example
ServerAlias www.example.dev

WSGIDaemonProcess example python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example
WSGIScriptAlias / /home/example/saas/wsgi.py


<Directory /home/example/static>
Require all granted
</Directory>

<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName example.dev


DocumentRoot /home/example
ServerAlias example.dev

WSGIDaemonProcess example2 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example2
WSGIScriptAlias / /home/example/saas/wsgi.py

Alias /static/ /home/example/static/

<Directory /home/example/static>
Require all granted
</Directory>

<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName example.dev

DocumentRoot /home/example
ServerAlias *.example.dev

WSGIDaemonProcess example3 python-path=/home/example:/home/venv/example/lib/python2.7/site-packages
WSGIProcessGroup example3
WSGIScriptAlias / /home/example/saas/wsgi.py

Alias /static/ /home/example/static/
<Directory /home/example/static>
Require all granted
</Directory>

<Directory /home/example/saas>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

谢谢!

【问题讨论】:

    标签: django apache ubuntu mod-wsgi


    【解决方案1】:

    我会留下这个问题,以防这对其他人有帮助,但我找到了解决方案......我忘记了我没有重新启动 dnsmasq,所以在将 address=/.example.dev/127.0.0.1 行添加到 /etc/dnsmasq.conf 之后并使用sudo /etc/init.d/dnsmasq restart 重新启动 dnsmasq 我能够访问子域上的站点。糟糕!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-28
      • 2021-06-01
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 2022-12-30
      • 1970-01-01
      相关资源
      最近更新 更多