以https方式访问apache服务器的配置以及nfs挂载

目录

1.配置使用ssl完成https访问apache服务器

2.配置访问apache的cgi程序

3.nfs挂载

4.autofs自动挂载远程nfs服务器目录为/nfs/autofs,客户端的挂载目录/data/autofs,且设置自动卸载时间为60秒

5.使用https来访问的web服务器要求使用自签名的CA签名证书(openssl, x.509) .crt,以及私钥


1.配置使用ssl完成https访问apache服务器

#设置ssl要访问的目录和index.html
[root@server www]# mkdir myssl
[root@server www]# cd myssl/
[root@server myssl]# echo "This is my first https page" > index.html
[root@localhost ~]# vim /etc/httpd/conf.d/myssl.conf 
<Directory "/www/myssl">
        AllowOverride None
        Require all granted
</Directory>

<VirtualHost 192.168.5.200:443>
        SSLEngine on
        SSLProtocol all -SSLv3
        SSLCipherSuite PROFILE=SYSTEM  #加密套件
        SSLCertificateFile /etc/pki/tls/certs/localhost.crt  #证书位置(自动生成)
        SSLCertificateKeyFile /etc/pki/tls/private/localhost.key	#私钥位置(自动生成)
        DocumentRoot "/www/myssl"
</VirtualHost>
[root@localhost ~]# systemctl restart httpd
[root@server ~]# curl --insecure https://192.168.5.200
This is my first https page

2.配置访问apache的cgi程序

[root@server ~]# vim /www/mybin/test.cgi 
#!/bin/bash
printf "Content-Type: text/html;charset=utf-8\n\n";	
printf "Hello, World.";	
#修改权限
[root@server mybin]# chmod 755 /www/mybin/test.cgi 
[root@server mybin]# ll /www/mybin/test.cgi 
-rwxr-xr-x 1 root root 89 Jul 30 20:58 /www/mybin/test.cgi
[root@server ~]# vim /etc/httpd/conf.d/myhosts.conf
<Directory "/www/ip">
        AllowOverride None
        Require all granted
</Directory>
<Directory "/www/mybin">
        AllowOverride None
        Require all granted
</Directory>

<VirtualHost 192.168.5.100:80>
        DocumentRoot "/www/ip/100"
        ScriptAlias "/bin" "/www/mybin"
</VirtualHost>
<VirtualHost 192.168.5.200:80>
        DocumentRoot "/www/ip/200"
</VirtualHost>
[root@server mybin]# systemctl restart httpd
[root@server mybin]# curl 192.168.5.100/bin/test.cgi
Hello, World.[root@server mybin]# 

3.nfs挂载

a、开放/nfs/shared目录,供所有用户查询资料;

服务端:

[root@server ~]# vim /etc/exports
/nfs/shared     *(ro)
[root@server ~]# mkdir -p /nfs/shared
[root@server ~]# cd /nfs/shared/
[root@server shared]# echo 123 > share.txt
[root@server shared]# systemctl restart rpcbind
[root@server shared]# systemctl restart nfs-server
[root@server shared]# showmount -e 192.168.5.128
Export list for 192.168.5.128:
/nfs/shared *

客户端:

[root@client ~]# showmount -e 192.168.5.128
Export list for 192.168.5.128:
/nfs/shared *
[root@client ~]# mount 192.168.5.128:/nfs/shared /mnt
[root@client ~]# cd /mnt/
[root@client mnt]# ll
total 4
-rw-r--r--. 1 root root 4 Jul 30 21:25 share.txt

b、开放/nfs/upload目录,该目录为192.168.xxx.0/24网段的主机的数据上传目录,并将所有该网段主机上传文件的所属者和所属组映射为nfs-upload,其UID和GID为2001;

服务端:

[root@server shared]# mkdir /nfs/upload
[root@server shared]# useradd -u 2001 nfs-upload
[root@server shared]# vim /etc/exports
/nfs/shared     *(ro)
/nfs/upload     192.168.5.0/24(rw,all_squash,anonuid=2001,anongid=2001)
[root@server nfs]# chmod o+w /nfs/upload/
[root@server nfs]# ll -d upload/
drwxr-xrwx 2 root root 6 Jul 30 21:57 upload/
[root@server shared]# systemctl restart rpcbind  
[root@server shared]# systemctl restart nfs-server

客户端:

[root@client ~]# mount 192.168.5.128:/nfs/upload /upload
[root@client upload]# touch test.txt
[root@client upload]# ll
total 0
-rw-r--r--. 1 2001 2001 0 Jul 30 22:03 test.txt

服务端:

[root@server nfs]# ll upload/
total 0
-rw-r--r-- 1 nfs-upload nfs-upload 0 Jul 30 22:03 test.txt

c、将/home/tom(该目录为uid=1111,gid=1111的tom用户的家目录)目录仅共享
给192.168.xxx.129这台主机上的jerry用户,jerry对该目录具有访问、新建和删除文件的权限。

服务端:

[root@server nfs]# useradd -u 1111 tom
[root@server nfs]# vim /etc/exports
/nfs/shared     *(ro)
/nfs/upload     192.168.5.0/24(rw,all_squash,anonuid=2001,anongid=2001)
/home/tom       192.168.5.129/255.255.255.0(rw,all_squash,anonuid=1111,anongid=1111)
[root@server nfs]# systemctl restart rpcbind
[root@server nfs]# systemctl restart nfs-server

客户端:

[root@client ~]# useradd -u 1111 jerry
[root@client ~]# mkdir /tom
[root@client ~]# showmount -e 192.168.5.128
Export list for 192.168.5.128:
/nfs/shared *
/home/tom   192.168.5.129/255.255.255.0
/nfs/upload 192.168.5.0/24
[root@client ~]# mount 192.168.5.128:/home/tom /tom
[root@client ~]# cd /tom
[root@client tom]# touch test.txt
[root@client tom]# ll
total 0
-rw-r--r--. 1 jerry jerry 0 Jul 30 22:36 test.txt
[root@client tom]# rm -f test.txt 
[root@client tom]# ll
total 0

4.autofs自动挂载
远程nfs服务器目录为/nfs/autofs,客户端的挂载目录/data/autofs,且设置自动卸载时间为60秒

服务端:

[root@server nfs]# vim /etc/exports
/nfs/shared     *(ro)
/nfs/upload     192.168.5.0/24(rw,all_squash,anonuid=2001,anongid=2001)
/home/tom       192.168.5.129/255.255.255.0(rw,all_squash,anonuid=1111,anongid=1111)
/nfs/autofs     *(ro)
[root@server nfs]# mkdir /nfs/autofs
[root@server nfs]# echo 123 > /nfs/autofs/test.txt
[root@server nfs]# systemctl restart rpcbind
[root@server nfs]# systemctl restart nfs-server

客户端:

[root@client tom]# vim /etc/auto.master
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/data    /etc/auto.mynfs    --timeout 60
/misc   /etc/auto.misc
…………
[root@client tom]# vim /etc/auto.mynfs 
autofs    192.168.5.128:/nfs/autofs
[root@client tom]# mkdir -p /data/autofs
[root@client tom]# systemctl restart autofs
[root@client tom]# mount | grep /data
/etc/auto.mynfs on /data type autofs (rw,relatime,fd=6,pgrp=3474,timeout=60,minproto=5,maxproto=5,indirect,pipe_ino=53804)


#触发自动挂载
[root@client ~]# cd /data/autofs
[root@client autofs]# mount | grep /data/autofs
192.168.5.128:/nfs/autofs on /data/autofs type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.5.129,local_lock=none,addr=192.168.5.128)

5.使用https来访问的web服务器
要求使用自签名的CA签名证书(openssl, x.509) .crt,以及私钥

生成 RSA 私钥和自签名证书

openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 365 -out cert.crt

req是证书请求的子命令,-newkey rsa:2048 -keyout private_key.pem 表示生成私钥(PKCS8格式),-nodes 表示私钥不加密,若不带参数将提示输入密码;
-x509表示输出证书,-days365 为有效期,此后根据提示输入证书拥有者信息;
若执行自动输入,可使用-subj选项:

openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 365 -out cert.crt -subj "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=vivo.com/emailAddress=yy@vivo.com"
#生成私钥和自签名证书
[root@server ~]# mkdir my_key_cert
[root@server ~]# cd my_key_cert/
[root@server my_key_cert]# openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 365 -out cert.crt -subj "/C=CN/ST=GD/L=SZ/O=vihoo/OU=dev/CN=vivo.com/emailAddress=yy@vivo.com"
[root@server my_key_cert]# ls
cert.crt  rsa_private.key
#设置ssl要访问的目录和index.html
[root@server www]# mkdir mycert
[root@server www]# cd mycert/
[root@server mycert]# echo "This is my first cert page" > index.html
[root@localhost ~]# vim /etc/httpd/conf.d/myssl.conf 
<Directory "/www/mycert">
        AllowOverride None
        Require all granted
</Directory>

<VirtualHost 192.168.5.128:443>
        SSLEngine on
        SSLProtocol all -SSLv3
        SSLCipherSuite PROFILE=SYSTEM
        SSLCertificateFile /root/my_key_cert/cert.crt            #生成的证书位置
        SSLCertificateKeyFile /root/my_key_cert/rsa_private.key  #生成的私钥位置
        DocumentRoot "/www/mycert"
</VirtualHost>
[root@localhost ~]# systemctl restart httpd
[root@server mycert]# systemctl restart httpd
[root@server mycert]# curl --insecure https://192.168.5.128
This is my first cert page

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我可以为您提供一些相关的指导建议,帮助您在服务器上部署一个简易下载站点和NFS网络存储,以及添加状态页面和限制用户访问。 1. 安装和配置Web服务器 首先,您需要选择一个Web服务器软件,例如Apache或Nginx,并安装和配置它。这里以Apache为例,您可以按照如下步骤进行操作: - 安装Apache 您可以使用以下命令在Ubuntu系统上安装Apache: ``` sudo apt-get update sudo apt-get install apache2 ``` - 配置Apache 配置Apache主要包括修改站点根目录、添加虚拟主机等操作。您可以修改配置文件/etc/apache2/sites-available/000-default.conf,例如: ``` <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> ``` 这里的DocumentRoot表示站点根目录,您可以将您想要提供下载的文件放置在该目录下。 2. 安装和配置NFS服务器 接下来,您需要安装和配置NFS服务器,以便将其挂载到站点根目录下。 - 安装NFS 您可以使用以下命令在Ubuntu系统上安装NFS: ``` sudo apt-get update sudo apt-get install nfs-kernel-server ``` - 配置NFS 您需要编辑/etc/exports文件,在其中加入您要分享的目录和相关配置,例如: ``` /home/nfs-share *(rw,sync,no_subtree_check) ``` 其中/home/nfs-share是您要分享的目录,*表示允许所有客户端访问,rw表示可读写,sync表示同步写入数据,no_subtree_check表示不进行子目录检查。 3. 添加状态页面 添加状态页面可以使用一些现成的工具,例如Cacti、MRTG、Nagios等。这里以Cacti为例,您可以按照如下步骤进行操作: - 安装Cacti 您可以使用以下命令在Ubuntu系统上安装Cacti: ``` sudo apt-get update sudo apt-get install cacti ``` - 配置Cacti 配置Cacti包括设置数据库、添加设备等操作。您可以使用以下命令进行配置: ``` sudo cacti-setup ``` 4. 限制用户访问 您可以添加身份验证和授权机制,以限制用户访问。例如,您可以使用基于用户名和密码的身份验证,或者使用IP地址过滤等。 - 基于用户名和密码的身份验证 您可以使用Apache提供的基于用户名和密码的身份验证功能,例如: ``` sudo htpasswd -c /etc/apache2/.htpasswd username ``` 其中username是您要设置的用户名,系统会提示您输入密码。然后,您需要编辑/etc/apache2/sites-available/000-default.conf文件,添加以下内容: ``` <Directory /var/www/html> AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/apache2/.htpasswd Require valid-user </Directory> ``` 这里的/var/www/html是您站点根目录的路径。 - 使用IP地址过滤 您可以使用Apache提供的IP地址过滤功能,例如: ``` sudo vi /etc/apache2/sites-available/000-default.conf ``` 在文件末尾添加以下内容: ``` <Directory /var/www/html> Order Deny,Allow Deny from all Allow from 192.168.1.0/24 </Directory> ``` 这里的192.168.1.0/24表示允许192.168.1.0/24网段的IP地址访问站点。 希望这些指导建议对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

俗人不俗鸭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值