web相关小实验

夙堇 2024-08-05 13:03:01 阅读 80

root@localhost html]# cd /etc/httpd/conf.d

[root@localhost conf.d]# vim vhost.conf

{

<directory "/testweb">

allowoverride none

require all granted

</directory>

<virtualhost *:80>

servername   192.168.119.131

documentroot   /testweb

</virtualhost>

}

[root@localhost conf.d]# systemctl restart httpd

完成!

【基于不同端口的web服务器】

[root@localhost html]# cd /etc/httpd/conf.d

[root@localhost conf.d]# vim vhost.conf

</directory>

<virtualhost *:80>

servername   192.168.119.131

documentroot   /testweb

</virtualhost>

<directory "/testweb2">

 allowoverride none

 require all granted

</directory>

listen 81

<virtualhost *:81>

servername 192.168.119.131

documentroot  /testweb2

</virtualhost>

[root@localhost conf.d]# systemctl restart httpd   

[root@localhost conf.d]# netstat -lntup | grep httpd

tcp6       0      0 :::81                   :::*                    LISTEN      38748/httpd         

tcp6       0      0 :::80                   :::*                    LISTEN      38748/httpd         

完成!

【基于不同主机名的web服务器】

[root@localhost conf.d]# vim vhost.conf

{

<directory "/testweb3">

 allowoverride none

 require all granted

</directory>

<virtualhost *:80>

servername   www.haha.com

documentroot   /testweb3

</virtualhost>

}

[root@localhost conf.d]# systemctl restart httpd

[root@localhost conf.d]# vim /etc/hosts

{

192.168.119.131 www.haha.com

}

完成!

【】

1、配置仓库,安装软件包

2、写配置文件

    1、定义web服务器虚拟主机的文件目录

        1、  allowoverride none

        2、  require all granted

    2、定义虚拟主机

        1、  documentroot

        2、  servername

    3、web文件目录创建

3、启动服务器    systemctl start httpd

4、查看服务状态  systemctl status httpd

【加密的web服务器】

5、加密的,   dnf install mod_ssl  ssl.conf或者yum install mod_ssl  -y

[root@localhost conf.d]# vim vhost.conf

    SSLEngine on

    SSLCertificateFile /etc/pki/tls/certs/jiami.crt  路径一定要写对

    SSLCertificateKeyFile /etc/pki/tls/private/jiami.key  路径一定要写对

6、创建证书和私钥 

[root@localhost ~]# cd /etc/pki/tls/certs/

[root@localhost certs]#openssl genrsa > jiami.key

[root@localhost certs]#openssl req -utf8 -new -key jiami.key -x509 -days 100 -out jiami.crt

7、一定要注意证书和私钥的路径(把key的路径移动到private下:[root@localhost certs]# mv jiami.key ../private/)

       /etc/pki/tls/certs/

       私钥和证书要匹配   

       0  

8、开启防火墙可以访问http、https的服务

9、  重启服务 查看服务状态   测试服务访问能力

【用户认证的web服务器】

1、   创建用户认证的密码文件

[root@localhost tls]# htpasswd -c(第一次添加) /etc/httpd/zhanghao haha

New password: 

Re-type new password: 

Adding password for user haha

[root@localhost tls]# 

[root@localhost tls]# htpasswd /etc/httpd/zhanghao xixi

New password: 

Re-type new password: 

Adding password for user xixi

2、   创建需要用户认证的目录

[root@localhost tls]# mkdir /usr/local/mysecret

[root@localhost tls]# echo This is mysecrest > /usr/local/mysecret/index.html

3、   在虚拟主机中配置需要认证的web目录

<directory /usr/local/mysecret>

authtype basic

authname "suibianxie: "

authuserfile   /etc/httpd/zhanghao

require user haha  xixi

</directory>

{

<directory /testweb3>

allowoverride none

require all granted

</directory>

<directory /usr/local/mysecret>

authtype basic

authname "xxxx:"

authuserfile /etc/httpd/zhanghao

require user abc tom

</directory>

<virtualhost 192.168.119.131:443>

documentroot /testweb3

servername www.haha.com

alias /mysecret /usr/local/mysecret

SSLCertificateKeyFile "/etc/pki/tls/private/jiami.key"

SSLCertificateFile "/etc/pki/tls/certs/jiami.crt"

SSLEngine on

</virtualhost>

}

4、   重启服务器,查看服务器,访问服务

【基于Python的动态虚拟机】

1、安装python模块

[root@kittod conf.d # dnf install python3-mod_wsgi -y

2、脚本内容

[root@kittod conf.d # cat /var/www/cgi-bin/helloworld.wsgi

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]

3、配置文件内容

[root@kittod conf.d # cat host.conf

<directory /www>

allowoverride none

require all granted

</directory>

<virtualhost 192.168.226.130: 80>

servername www.haha.com

WSGIScriptAlias / /var/www/cgi-bin/helloworld.wsgi

</virtualhost>

4、 重启服务



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。