[英]Django project on 80 port?
Ι have developed a Django project and uploaded it to a cloud VΜ.我已经开发了一个 Django 项目并将其上传到云 VM。 Currently i have access to it through 8080 port.
目前我可以通过 8080 端口访问它。
python manage.py runserver 0.0.0.0:8080
If i enter the url without the 8080 port, it shows the "it works" page.如果我输入没有 8080 端口的 url,它会显示“它有效”页面。 How can i set my Django project to run by default on 80 port?
如何将我的 Django 项目设置为默认在 80 端口上运行?
I am using Ubuntu 12.04 server我正在使用 Ubuntu 12.04 服务器
Here is the kind of file you will need to put in /etc/apache2/sites-enabled, you need to adjust the paths in it.这是您需要放入 /etc/apache2/sites-enabled 中的文件类型,您需要调整其中的路径。 You also need to load mod_wsgi which you can do via apt-get.
您还需要加载 mod_wsgi,您可以通过 apt-get 来完成。
<VirtualHost 192.168.1.14:80>
ServerAdmin youremail@whatever.com
ServerName www.whatever.com
ServerAlias whatever.com
Alias /robots.txt /home/dimitris/Python/mysite/site_media/robots.txt
Alias /favicon.ico /home/dimitris/Python/mysite/site_media/favicon.png
Alias /static/ /home/dimitris/Python/mysite/site_media/static
WSGIDaemonProcess mysite user=dimitris processes=1 threads=5
WSGIProcessGroup mysite
WSGIScriptAlias / /home/dimitris/Python/mysite/deploy/mysqite_wsgi.py
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel debug
ErrorLog ${APACHE_LOG_DIR}/mysite.error.log
CustomLog ${APACHE_LOG_DIR}/mysite.access.log combined
ServerSignature Off
</VirtualHost>
Most of this assumes you are running in a virtualenv, that means you will need a wsgi file to get things running.其中大部分假设您在 virtualenv 中运行,这意味着您需要一个 wsgi 文件才能运行。 The above file sets up apache to run your "wsgi" file which looks something like this:
上面的文件设置 apache 来运行你的“wsgi”文件,它看起来像这样:
import os
from os.path import abspath, dirname, join
import sys
with open("/tmp/mysite.sys.path", "w") as f:
for i in sys.path:
f.write(i+"\n")
#redirect sys.stdout to sys.stderr for libraries that use
#print statements for optional import exceptions.
sys.stdout = sys.stderr
sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
sys.path.insert(0, abspath(join(dirname(__file__), "../../lib/python2.7/site-packages/")))
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
mod_wsgi, then opens this one file and executes it. mod_wsgi,然后打开这个文件并执行它。 application is the part that waits for requests from the webserver, and the rest behaves just like runserver except it can be multi-process and multi-threaded.
application 是等待来自 webserver 的请求的部分,其余部分的行为与 runserver 一样,只是它可以是多进程和多线程的。
In the terminal while in a virtual environment, run:在虚拟环境中的终端中,运行:
sudo ./manage.py runserver 80
You will be asked for your password and it will run the server on port 80.系统会要求您输入密码,它会在端口 80 上运行服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.