ssh免密登陆,nginx配置web服务练习

要求

1、配置linux客户端免密登录服务端linux主机的root用户
2、配置web服务器,当访问网站www.haha.com时显示:haha
3、配置web服务器,当访问网站www.xixi.com/secret/显示:this is secret

一、配置linux客户端免密登录服务端linux主机的root用户

1、在SSH服务器所在机器上#

(1)、以root用户登录,更改ssh配置文件 /etc/ssh/sshd_config,去除以下配置的注释

RSAAuthentication yes #启用rsa认证
PubkeyAuthentication yes #启用公钥私钥配对认证方式
AuthorizedKeysFile .ssh/authorized_keys #公钥文件路径

(2)、重启SSH服务

[root@server /]#systemctl restart sshd  //重启ssh服务

2、在客户端机器上#

(1)、生成公钥和私钥

[root@client /]#ssh-keygen -t rsa
一路默认回车,系统在/root/.ssh下生成id_rsa、id_rsa.pub

(2)、把id_rsa.pub发送到服务端机器上

[root@client /]#ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.126.136

(3)、验证

[root@client /]#ssh root@192.168.126.136 #server ip

二、配置web服务器,当访问网站www.haha.com时显示:haha

(1)、在/etc/hosts文件中添加IP对应的域名

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.128 www.haha.com

(2)、创建静态资源存放的目录

[root@128-service data]# tree
.
├── haha
│   └── index.html
└── nginx
    ├── haha.txt
    ├── hello.html
    └── ykzhaopian.jpg

2 directories, 4 files

(3)、添加服务配置文件在/etc/nginx/conf.d/*.conf;

[root@128-service conf.d]# tree
.
├── haha.conf
└── static.conf

0 directories, 2 files
[root@128-service conf.d]# pwd
/etc/nginx/conf.d

(4)、编辑haha.conf

server {
        listen 192.168.48.128:80;   #监听的IP和端口
        server_name www.haha.com;       #服务器名称
        root /data/haha;            #服务的根目录
         location / {index index.html;}              #设置了默认的索引文件为index.html
}

(5)、检查语法,重启nginx

  nginx -t
  nginx -s reload

(6)使用curl获取指定的URL

[root@128-service conf.d]# curl www.haha.com
haaa

三、配置web服务器,当访问网站www.xixi.com/secret/显示:this is secret

(1)、在/etc/hosts文件中添加IP对应的域名

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.48.128 www.haha.com
192.168.48.110 www.xixi.com	# 添加IP对应的域名

(2)、创建静态资源存放的目录

[root@128-service xixi]# tree /data/xixi
/data/xixi
└── secret
    └── index.html

1 directory, 1 file

(3)、添加服务配置文件在/etc/nginx/conf.d/*.conf;

server {
        listen 192.168.48.110:80;   #监听的IP和端口
        server_name www.xixi.com;       #服务器名称
        root /data/xixi;            #服务的根目录
         location / {}              #设置了默认的索引文件为index.html
}

(5)、检查语法,重启nginx

[root@128-service xixi]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@128-service xixi]# nginx -s relaod
nginx: invalid option: "-s relaod"
[root@128-service xixi]# nginx -s reload

(6)使用curl获取指定的URL

[root@128-service xixi]# curl www.xixi.com/secret/
this is secret
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值