CentOS 7.2配置Apache服务httpd(上)

2019-01-17 02:14:19刘景俊

六、支持Python

启用CGI执行并使用Python脚本

[1] 安装python. [root@linuxprobe ~]# yum -y install python [2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。 可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。 # 下面的设置是CGI的设置 [root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf 247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" [3] 如果你想允许在其他目录中的CGI,配置如下。 例如,在“/var/www/html/cgi-enabled”中允许。 [root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf # create new # processes .py as CGI scripts <Directory "/var/www/html/cgi-enabled"> Options +ExecCGI AddHandler cgi-script .py </Directory> [root@linuxprobe ~]# systemctl restart httpd [4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。 [root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled [root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled [5] Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown. [root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.py #!/usr/bin/env python print "Content-type: text/htmlnn" print "<html>n<body>n" print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">n" print "Python Script Test Page" print "n</div>n" print "</body>n</html>n" [root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.py

七、支持Userdir

启用userdir,用户可以使用此设置创建网站

[1] 配置 httpd. [root@linuxprobe ~]# vi /etc/httpd/conf.d/userdir.conf # line 17: comment out #UserDir disabled # line 24: uncomment UserDir public_html # line 31 - 35 <Directory "/home/*/public_html"> AllowOverride All # change Options None # change Require method GET POST OPTIONS </Directory> [root@linuxprobe ~]# systemctl restart httpd [2] 创建一个测试页,使用普通用户通过客户端PC与Web浏览器和访问它,如果显示以下页面,就是正确的 [cent@linuxprobe ~]$ mkdir public_html [cent@linuxprobe ~]$ chmod 711 /home/cent [cent@linuxprobe ~]$ chmod 755 /home/cent/public_html [cent@linuxprobe ~]$ vi ./public_html/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> UserDir Test Page </div> </body> </html>

浏览器访问:http://linuxprobe.org/~wang/,出现如下界面