apache部署三

1.php语言

php语言编写的网站显示
yum install php -y
[root@localhost conf.d]# cd /var/www/html/
[root@localhost html]# vim index.php
<?php
	phpinfo( );
?>
 systemctl restart httpd

测试端:172.25.254.229/index.php

 

 

测试端进行测试:

2.cgi的per语言:

cgi语言:
1.[root@localhost html]# cd /var/www
[root@localhost www]# ls
cgi-bin  html  westos.com
[root@localhost www]# cd cgi-bin/
[root@localhost cgi-bin]# ls -Zd .
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 .
[root@localhost cgi-bin]# vim index.cgi

  1 #!/usr/bin/perl
  2 print "Content-type: text/html\n\n";
  3 print `date`;

chmod +x index.cgi 

测试端测试:172.25.254.129/cgi-bin/index.cgi

 

如果我们再网页中是直接想找到cgi写的网页,向上面这种输入的话,很麻烦,那我们可以更改一下他的输入路径:

[root@localhost conf.d]# systemctl restart httpd.service 
[root@localhost conf.d]# cd /var/www/html/
[root@localhost html]# ls
index.html  index.php  mysqladmin  westos.html
[root@localhost html]# mkdir cgi
[root@localhost html]# ls
cgi  index.html  index.php  mysqladmin  westos.html
[root@localhost html]# cd cgi/

[root@localhost cgi]# cp /var/www/cgi-bin/index.cgi .
[root@localhost cgi]# ls
index.cgi
[root@localhost cgi]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ls
a_default.conf  http_userlist  news.conf  README        welcome.conf
autoindex.conf  music.conf     php.conf   userdir.conf
[root@localhost conf.d]# vim a_default.conf 

 <VirtualHost _default_:80>
  2                 DocumentRoot /var/www/html
  3                 CustomLog logs/default.log combined
  4 </VirtualHost>
<Directory "/var/www/html/cgi">
 21         Options ExecCGI
 22         AddHandler cgi-script .cgi
 23 </Directory>

[root@localhost conf.d]# ls -Zd .
drwxr-xr-x. root root system_u:object_r:httpd_config_t:s0 .
[root@localhost conf.d]# ls -Zd /var/www/cgi-bin/
drwxr-xr-x. root root system_u:object_r:httpd_sys_script_exec_t:s0 /var/www/cgi-bin/
[root@localhost conf.d]# semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'
[root@localhost conf.d]# restorecon -RvvF /var/www/html/cgi/
[root@localhost conf.d]# systemctl restart httpd.service 

在/etc/httpd/conf.d/下编辑默认的配置文件:

这是由于selinux原因:

我们更改安全上下文:

 

现在就可以成功访问了:

网页重写:

https
 yum install mod_ssl -y
cd /etc/httpd/conf.d/
ls
多了个文件
 ssl.conf
 yum install crypto-utils.x86_64
systemctl restart httpd
此时可以在测试端登陆
https://172.25.254.129
但此时的加密是默认的


自己设置加密key
 yum install crypto-utils.x86_64
 genkey www.westos.com
shell中出现提示:

output will be written to /etc/pki/tls/certs/www.westos.com.crt
output key written to /etc/pki/tls/private/www.westos.com.key

[root@localhost conf.d]# vim ssl.conf 
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
108 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
ystemctl restart httpd.service 

测试端:https://172.25.254.129

 

 

 

 

 

但是此时的网页还不能自动跳转为https

我们需要对配置文件。进行修改:

 

1 <VirtualHost *:443>
  2         ServerName login.westos.com
  3         DocumentRoot /var/www/html/virtual/login.westos.com/html
  4         CustomLog "logs/login.logs" combined
  5         SSLEngine on
  6         SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
  7         SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
  8 </VirtualHost>
  9 <Directory "/var/www/html/virtual/login.westos.com/html">
 10         Require all granted
 11 </Directory>
 12 <VirtualHost *:80>
 13         ServerName login.westos.com
 14         RewriteEngine On
 15         RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
 16 </VirtualHost>

此时再次测试时,是可以自动跳转为https

 

apache支持python

1.yum install mod_wsgi.x86_64 apache支持python语言的模块
2.cd /var/www/cgi-bin/
 wget http://172.25.254.250/pub/materials/webapp.wsgi-----用python语言编写的网页脚本
这里我已经拷贝过来了,就不需要输入上一行了
3.cd /etc/httpd/conf.d/
vim webapp.conf

 1 <VirtualHost *:80>
  2         ServerName webapp.westos.com
  3         DocumentRoot /var/www/cgi-bin
  4         CustomLog logs/webapp.log comined
  5         WSGIScriptAlias / /var/www/cgi-bin/webapp.wsgi
  6 </VirtualHost>

4.systemctl restart httpd

服务端:vim /etc/hosts
加上webapp.westos.com
浏览器输入webapp.westos.com

 

在真机上

测试:

 

但是安装的时候发现一部分不能安装:

 

这是由于seinux的原因:

 

此时就可以安装了:

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值