2024-05-23 13:30:49 发布
网友
我最近完成了django2应用程序的开发,部分需求是将其部署到centos机器上的apache2服务器上。 django应用程序是用python3编写的,centos机器预装了python2。在
到目前为止,我在apache2服务器上安装mod_wsgi并部署应用程序时遇到了困难。在
任何帮助都将不胜感激。在
编辑 我已经解决了这个问题。请看下面我的答案
我保证百胜是最新的:
$ yum update
编译器和相关工具:
编译期间启用Python所有功能所需的库:
$ yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite- devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
安装Python 3.6.5:
$ wget http://python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz $ tar xf Python-3.6.5.tar.xz $ cd Python-3.6.5 $ ./configure prefix=/usr/local enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" $ make && make altinstall
使用刚刚安装的python3.6运行以下命令
$python3.6 -m pip install mod_wsgi
找到apache配置文件/etc/apache2/conf/http.conf并通过指定安装路径添加以下命令来加载mod_wsgi。 在我的例子中,将loadModule命令添加到/etc/apache2/conf.d/includes/pre_main_全球会议在
$ LoadModule wsgi_module /usr/local/lib/python3.6/site- packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
$apachectl restart $apachectl -M
查看列表,确保mod_wsgi是apache加载的模块的一部分。在
我有一个服务器,已经托管7个不同的网站。我只是创建了一个新的子域并修改了子域virtualhost
<VirtualHost mysite.com_ip:80> ServerName wsgitest.mysite.com ServerAlias www.wsgitest.mysite.com DocumentRoot /home/account_username/public_html/wsgitest ServerAdmin admin@mysite.com <Directory /home/account_username/public_html/wsgitest> Order allow,deny Allow from all </Directory> WSGIScriptAlias / /home/account_username/public_html/wsgitest/hello.py ErrorLog /home/account_username/public_html/wsgitest/wsgitest_error.log </VirtualHost>
修改虚拟主机后重新启动apache
创建你好.py根据此站点的wsgi应用程序-http://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
def application(environ, start_response): status = '200 OK' output = b'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
所以我的wsgitest应用程序在服务器上看起来像这样 /home/account_用户名/public_html/wsgitest/你好.py在
最后,在浏览器上测试站点,如下所示-wsgitest.mysite.com网站 你应该看看“你好世界”
我希望这对某人有帮助
1。将python3.6.5干净地安装到usr/local和usr/local/lib
我保证百胜是最新的:
编译器和相关工具:
^{pr2}$编译期间启用Python所有功能所需的库:
安装Python 3.6.5:
2。使用pip install安装mod_wsgi
使用刚刚安装的python3.6运行以下命令
3。将Mod_wsgi加载到apache模块中
找到apache配置文件/etc/apache2/conf/http.conf并通过指定安装路径添加以下命令来加载mod_wsgi。 在我的例子中,将loadModule命令添加到/etc/apache2/conf.d/includes/pre_main_全球会议在
4。重新启动Apache服务器并确认mod_wsgi已加载
查看列表,确保mod_wsgi是apache加载的模块的一部分。在
5。配置和执行简单的虚拟主机你好.py试验
我有一个服务器,已经托管7个不同的网站。我只是创建了一个新的子域并修改了子域virtualhost
修改虚拟主机后重新启动apache
创建你好.py根据此站点的wsgi应用程序-http://modwsgi.readthedocs.io/en/develop/user-guides/quick-configuration-guide.html
在你好.py在
所以我的wsgitest应用程序在服务器上看起来像这样 /home/account_用户名/public_html/wsgitest/你好.py在
最后,在浏览器上测试站点,如下所示-wsgitest.mysite.com网站 你应该看看“你好世界”
我希望这对某人有帮助
相关问题 更多 >
编程相关推荐