Apache-2.2
無法獲取在 Django Apache EC2 上工作的 URL
這是我第一次嘗試使用 Django 設置網路伺服器。一段時間以來,我一直在努力嘗試進行設置,但我似乎找不到任何資源可以逐步格式化新手來解釋這一點。
我已經在我的 EC2 實例上安裝並設置了 apache 和 mod_wsgi。如何將我的 urls.py 文件中設置的應用程序的 URL 映射到 apache?在本地,我可以
127.0.0.1:8000/flickr/photousers
通過在 Django 開發伺服器上執行我的應用程序來執行我的輸入。我試圖讓它在我的公共 dns 上http://ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com/flickr/photouser
與 apache 和 mod_wsgi 一樣工作。當我重新啟動 Apache 伺服器時,我也收到此錯誤,但狀態正常
[error] (EAI 2)Name or service not known: Could not resolve host name *.80 -- ignoring
下面列出了相關的片段
django.wsgi 文件
import os,sys apache_configuration = os.path.dirname(__file__) project = os.path.dirname(apache_configuration) workspace = os.path.dirname(project) sys.path.append(workspace) sys.path.append(/home/djangotest/flickr) #sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'flickr.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
httpd.conf 文件
<VirtualHost *.80> DocumentRoot /home/djangotest/flickr ServerName ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com ErrorLog /home/djangotest/flickr/logs/apache_error.log CustomLog /home/djangotest/flickr/logs/apache_access.log combined WSGIScriptAlias / /home/djangotest/flickr/apache/django.wsgi <Directory /home/djangotest/flickr/media> Order deny,allow Allow from all </Directory> <Directory /home/djangotest/flickr/apache> Order deny,allow Allow from all </Directory> LogLevel warn WSGIDaemonProcess ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com user=djangotest processes=2 threads=25 WSGIProcessGroup ec2-122-248-194-176.ap-southeast-1.compute.amazonaws.com Alias /media/ /home/djangotest/flickr/media/ </VirtualHost>
urls.py
from django.conf.urls.defaults import * urlpatterns = patterns('', # Example: (r'flickr/', include('flickrphotobrowser.urls')), )
urls.py(位於我的應用程序中)
from django.conf.urls.defaults import * from flickrphotobrowser.views import * urlpatterns = patterns('flickrphotobrowser.views', (r'^phototags/$', contenttags), (r'^photouser/$', contentuser), )
settings.py
ROOT_URLCONF = 'flickr.urls' TEMPLATE_DIRS = ( os.path.join(os.path.basename(__file__), 'templates'), #'home/nai/Projects/flickr/flickrphotobrowser/templates', # THIS IS FOR LOCAL ONLY ) INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'flickr.flickrphotobrowser', )
我是否應該包含任何其他片段來幫助解決問題?謝謝。
在您的 httpd conf 中,更改:
<VirtualHost *.80>
到
<VirtualHost *:80>
並重新啟動 Apache。
如果這不能解決它,您還可以嘗試添加:
sys.path.append('/home/djangotest')
到你的 django.wsgi 文件。