如何使用 mod wsgi 在 Apache2 上接收子域通配符?
How do I receive subdomain wildcards on Apache2 using mod wsgi?
我正在使用 Django 1.8 开发应用程序,我正在尝试接收子域,然后显示依赖于子域的自定义主页。例如:example.com 是我公司的主页,用户注册为 conqueryor.example.com,他们得到一个名为 "conqueryor.example.com" 或任何他们想要的新主页。
听起来很简单,甚至还有我正在使用的 django 子域库。我当前的问题在于在本地设置 Apache2 和 mod WSGI,这样我就可以在影响项目中的其他人之前在本地对其进行测试。我目前可以在我的 /etc/hosts 文件中使用以下带有行 127.0.0.1 example.dev
和 127.0.0.1 .example.dev
的 .conf 文件。在我的浏览器中,我可以从 example.dev 访问我的应用程序,但如果我尝试任何子域,我会收到“未找到服务器”页面。我也尝试过使用 dnsmasq 并添加行 address=/.example.dev/127.0.0.1
当前环境:
Ubuntu 15.10
姜戈 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>
谢谢!
我将留下这个问题以防万一这对其他人有帮助,但我找到了解决方案...我忘记了我没有重新启动 dnsmasq,所以在将 address=/.example.dev/127.0.0.1
行添加到 /etc/dnsmasq.conf 并使用 sudo /etc/init.d/dnsmasq restart
重新启动 dnsmasq 我能够访问子域上的站点。糟糕!
我正在使用 Django 1.8 开发应用程序,我正在尝试接收子域,然后显示依赖于子域的自定义主页。例如:example.com 是我公司的主页,用户注册为 conqueryor.example.com,他们得到一个名为 "conqueryor.example.com" 或任何他们想要的新主页。
听起来很简单,甚至还有我正在使用的 django 子域库。我当前的问题在于在本地设置 Apache2 和 mod WSGI,这样我就可以在影响项目中的其他人之前在本地对其进行测试。我目前可以在我的 /etc/hosts 文件中使用以下带有行 127.0.0.1 example.dev
和 127.0.0.1 .example.dev
的 .conf 文件。在我的浏览器中,我可以从 example.dev 访问我的应用程序,但如果我尝试任何子域,我会收到“未找到服务器”页面。我也尝试过使用 dnsmasq 并添加行 address=/.example.dev/127.0.0.1
当前环境: Ubuntu 15.10 姜戈 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>
谢谢!
我将留下这个问题以防万一这对其他人有帮助,但我找到了解决方案...我忘记了我没有重新启动 dnsmasq,所以在将 address=/.example.dev/127.0.0.1
行添加到 /etc/dnsmasq.conf 并使用 sudo /etc/init.d/dnsmasq restart
重新启动 dnsmasq 我能够访问子域上的站点。糟糕!