部署並測試動態WSGI站點python
5.1問題web
本例要求爲站點webapp0.example.com配置提供動態Web內容,要求以下:vim
此虛擬主機偵聽在端口8909瀏覽器
測試網頁從如下地址下載,不要做任何更改app
http://classroom/pub/materials/webinfo.wsgiwebapp
從瀏覽器訪問http://webapp0.example.com:8909可接收到動態生成的Web頁面tcp
此站點必須能被example.com域內的全部系統訪問測試
5.2方案spa
爲httpd增長對Python網頁程序的支持,能夠安裝mod_wsgi模塊。關於此模塊的配置說明,建議參考軟件包提供的readme文檔。firefox
在SELinux處於Enforcing模式時,若要開放非80、81等常規Web端口,須要調整SELinux保護策略。
5.3步驟
實現此案例須要按照以下步驟進行。
步驟一:部署動態網頁文檔
1)建立網頁目錄
[root@server0~]#mkdir /var/www/webapp0
2)部署webinfo.wsgi網頁程序
[root@server0~]#cd /var/www/webapp0
[root@server0webapp0]#wget http://classroom/pub/materials/webinfo.wsgi
....
2016-11-27 01:52:26(16.0 MB/s)-‘webinfo.wsgi’saved[397/397]
[root@server0 webapp0]#cat webinfo.wsgi//檢查下載文件
#!/usr/bin/env python
import time
....
步驟二:配置新的虛擬主機http://webapp0.example.com:8909/
1)安裝mod_wsgi模塊軟件包
[root@server0~]#yum-y install mod_wsgi
....
2)爲新虛擬主機創建配置
[root@server0~]#vim /etc/httpd/conf.d/02-webapp0.conf
Listen 8909
<VirtualHost*:8909>
DocumentRoot/var/www/webapp0
ServerName webapp0.example.com
WSGIScriptAlias//var/www/webapp0/webinfo.wsgi
</VirtualHost>
3)調整SELinux策略,容許Web服務使用8909端口
列出當前許可的Web端口:
[root@server0~]#semanage port-l|grep^http_port
http_port_t tcp 80,81,443,488,8008,8009,8443,9000
添加新的Web端口:
[root@server0~]#semanage port-a-t http_port_t-p tcp 8909
[root@server0~]#
確認配置結果:
[root@server0~]#semanage port-l|grep^http_port
http_port_t tcp 8909,80,81,443,488,8008,8009,8443,9000
4)重啓系統服務httpd
[root@server0~]#systemctl restart httpd
[root@server0~]#netstat-antpu|grep httpd//確認已監聽8909端口
tcp6 0 0:::443:::*LISTEN 2477/httpd
tcp6 0 0:::8909:::*LISTEN 2477/httpd
tcp6 0 0:::80:::*LISTEN 2477/httpd
步驟三:測試動態網頁效果
使用elinks或firefox訪問此動態站點http://webapp0.example.com:8909/。
多刷新訪問幾回,每次看到的是動態網頁內容,內容並不固定。
[root@desktop0~]#elinks -dump http://webapp0.example.com:8909/
UNIX EPOCH time is now:1480184916.52//第1次訪問
[root@desktop0~]#elinks -dump http://webapp0.example.com:8909/
UNIX EPOCH time is now:1480184919.21//第2次訪問
[root@desktop0~]#elinks -dump http://webapp0.example.com:8909/
UNIX EPOCH time is now:1480184951.99//第3次訪問