- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 django 的新手,这是我在 django 中的第一个项目。到目前为止,我已经开发了一个 django 应用程序。它在我的本地机器上运行流畅,但我无法在线部署它。
我在互联网上看到很多关于在服务器上部署应用程序的教程。但他们似乎都没有对我有用。可能是我在这里做错了什么。
https://www.youtube.com/watch?v=hBMVVruB9Vs https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/ https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps https://www.digitalocean.com/community/tutorials/how-to-run-django-with-mod_wsgi-and-apache-with-a-virtualenv-python-environment-on-a-debian-vps
我按照这些教程尝试在服务器上部署应用程序,但我总是收到 403 forbidden 错误。我试图消除此错误并引用了其他 stackoverflow 答案,但没有成功..
403 Forbidden error with Django and mod_wsgi
Apache mod_wsgi error: Forbidden You don't have permission to access / on this server
Django on apache wtih mod_wsgi (Linux) - 403 Forbidden
Installing Django with mod_wsgi
这是我为我的 Django 项目创建的结构。我的 Django 项目中有两个应用程序,我将我的一个应用程序连接到 DNS xyz.com
,我的第二个应用程序连接到它的子域 abc.xyz.com
。
结构
project_folder
|
|->app1
| |->urls.py
| |->template_folder
| |->static_folder
|->app2
| |->urls.py
| |->template_folder
| |->static_folder
|->project_name
|->urls.py
|->wsgi.py
project_name/urls.py
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^app1/', include('app1.urls')),
url(r'^app2/', include('app2.urls')),
]
app1/urls.py
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^example1/', views.example1),
url(r'^example2/', views.example2),
)
app2/urls.py
urlpatterns = patterns('',
url(r'^example3/', views.example3),
url(r'^example4/', views.example4),
)
基本上,我要做的是让我的 app1
在 xyz.com
上运行,而我的 app2
在 abc 上运行.xyz.com
(子域)。这样项目中的所有应用程序都具有相同的用户登录名。如果用户从一个应用程序登录,它也会登录到第二个应用程序。
在我的本地机器上,应用程序运行为
http://localhost:8000/app1/example1
http://localhost:8000/app1/example2
http://localhost:8000/app2/example3
http://localhost:8000/app2/example4
这是我在服务器上创建的 apache2 conf 文件
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName xyz.com
DocumentRoot /home/user_name/project_folder/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher | .py
PythonDebug On
</Directory>
<Directory /home/user_name/project_folder/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/user_name/project_folder/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/user_name/project_folder/access.log combined
</VirtualHost>
最佳答案
嗨,@Daniel Roseman 的评论是正确的。我再次浏览了文档并尝试了页面中提到的方式。我终于解决了这个问题。
我就是这样解决的..
app1.conf
<VirtualHost *:80>
ServerName xyz.com
WSGIScriptAlias / /var/www/html/project_folder/project_name/wsgi.py
WSGIDaemonProcess xyz.com python-path=/var/www/html/project_folder:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup xyz.com
<Directory /var/www/html/project_folder/project_name>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
使用命令 sudo a2ensite app1.conf
启用 app1.conf
文件。
对于域和子域,我使用了 django 包 django-subdomains
setting.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', # For include sites
'app1',
'ap2',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'subdomains.middleware.SubdomainURLRoutingMiddleware', # Subdomain package
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
SITE_ID = 1
ROOT_URLCONF = 'app1.urls'
SUBDOMAIN_URLCONFS = {
None: 'app1.urls',
'www': 'app1.urls',
'abc': 'app2.urls',
}
完成所有设置后运行命令 python manage.py migrate
。它将在数据库中创建一个包含一个条目的 django_site
表。将 example.com
更改为 xyz.com
。
为子域创建新的 app2.conf
文件并将 xyz.com
更改为 abc.xyz.com
。
关于python - 使用 mod_wsgi 部署具有域和子域的 django 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30477180/
大中型 python WSGI 应用,Apache + mod_wsgi 还是 Nginx + mod_wsgi 用什么? 哪种组合需要更多的内存和 CPU 时间? 哪个更快? 哪个以比另一个更稳定而
我通过 python CGI 脚本 (Apache2.4) 继承了在 AWS EC2 Windows 实例和 WAMP 服务器上运行的 Web 应用程序。我希望将 Web 应用程序转换为 Flask,
当我输入: [root@lts5 /]# ldd /usr/lib64/httpd/modules/mod_wsgi.so libpython2.5.so.1.0 => /root/epd-5
我正在尝试在 Ubuntu 16.04.6 服务器上部署带有 Apache2 和 mod_wsgi 的 Django 应用程序,但我正在努力让 mod_wsgi 使用正确的 python 版本。 我从
介绍 我有一个用 python 3 编写的 Web API,它使用 flask 。当我从终端运行 Web API 时,代码运行良好,它托管在代码的以下行中。 if __name__ == '__mai
我的 Django 项目中的 MemoryError 有一个奇怪的问题。 Ubuntu 11 Apache 2 Nginx mod_wsgi python2.7 我有一个使用 PIL 调整图像大小的模
在这里撕扯我的头发试图弄清楚为什么我的两个 Django 项目没有被分开提供......似乎首先访问的静态文件成为两个项目的事实上的静态文件,或者类似的东西。 我试图通过同一个 IP 地址的两个域名为
我正在通过发出一个需要 30 多分钟才能完成的请求来测试在 Apache Web 服务器上运行的 Python Flask Web 应用程序的限制。该请求需要向 MySQL 数据库发送数千个数据库请求
有谁知道如何制作mod_wsgi当任何模块更改时自动重新加载 Flask 应用程序?我试过WSGIScriptReloading On ,但没有运气。 official documentation有点
使用 mod_wsgi 部署应用程序时出现以下错误 [Thu Apr 07 11:23:32 2011] [error] [client localhost] IOError: [Errno 13]
我有用 Django 开发的普通内容管理网站。我的客户有一个具有 256 MB RAM 的服务器。他想以 wsgi 模式部署此站点。 256 MB RAM 是否足够?我对服务器 RAM 要求等一无所知
我对 Python 和 Python Web 应用程序开发比较陌生。目前我正在使用 mod_wsgi 在 Python 中创建一个 hello world 应用程序 这是我的配置。 Apache 配置
我有一个 wsgi 应用程序作为 mod_wsgi 守护进程(在守护进程模式下)运行。我的设置是每个守护进程在 1000 个请求后重新启动,如 mod_wsgi 配置指南中所示: http://cod
我在centos系统上安装了Postgres、mod_wsgi和python3.5。我已经测试了连接,它在交互式 Python shell 和开发应用程序中都运行良好(它是一个 Pyramid 应用程
我在 Centos 6 服务器上使用 Python Flask,mod_wsgi 突然不能工作了。 这是错误信息。 mod_wsgi (pid=6206): Target WSGI script '/
我一直在研究在运行 Python/mod_wsgi 的网络场中创建快速缓存的不同系统。 Memcache 和其他是选项......但我想知道: 因为我不需要跨机器共享数据,希望每台机器都维护一个本地缓
我在 apache2 上运行 mod_wsgi。它正在运行 Django,出于某种原因,在我更改代码后,旧版本有时会与新代码一起显示。 例如,在创建一个仅返回带“Hi”的 Http 响应的 View
当我尝试安装 mod_wsgi 时遇到以下错误 ./configure checking for apxs2... no checking for apxs... /usr/sbin/apxs che
我正在使用 Hostgator 开发 Linux Centos 虚拟主机。我使用的是 httpd 版本 2.2.15。 我使用标签 --with-python=/usr/local/bin/pytho
我使用 CherryPy、Apache 和 mod_wsgi 构建了一个网站,除了一个问题之外,一切都很好。当用户操作要求自动发送电子邮件时,我有时会使用 os.fork ,以便父进程可以立即返回并向
我是一名优秀的程序员,十分优秀!