我正在開發一個應用程序與Django 1.8,我試圖接收子域名,然後呈現依賴於子域的自定義主頁。例如:example.com是我公司的主頁,用戶註冊爲conqueryor.example.com,他們得到一個名爲「conqueryor.example.com」的新主頁或任何他們想要的東西。如何使用mod wsgi在Apache2上接收子域通配符?
聽起來很簡單,甚至還有我正在使用的django子域庫。我當前的問題在於在本地設置Apache2和mod WSGI,以便在影響項目中的其他人之前,我可以在本地進行測試。我目前能夠在我的/ etc/hosts文件中使用以下.conf文件,其行127.0.0.1 example.dev
和127.0.0.1 .example.dev
。在我的瀏覽器中,我可以從example.dev訪問我的應用程序,但如果我嘗試任何子域,則會收到「未找到服務器」頁面。 的Ubuntu 15.10 Django的1.8.1 的Apache 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
當前的環境下也試圖!