linux(centos)搭建简单apache服务

1.配置服务器IP地址

这里使用的是静态配置

 vi /etc/sysconfig/network-scripts/ifcfg-ens33	//配置ens33网卡配置文件
 cat /etc/sysconfig/network-scripts/ifcfg-ens33 
		TYPE=Ethernet
		PROXY_METHOD=none
		BROWSER_ONLY=no
		BOOTPROTO=static //将DHCP修改为static
		DEFROUTE=yes
		IPV4_FAILURE_FATAL=yes
		IPV6INIT=yes
		IPV6_AUTOCONF=yes
		IPV6_DEFROUTE=yes
		IPV6_FAILURE_FATAL=no
		IPV6_ADDR_GEN_MODE=stable-privacy
		NAME=ens33
		UUID=bb7e6267-5217-4aee-ac05-85ffad468956
		DEVICE=ens33
		ONBOOT=no
		IPADDR=192.168.10.102   //设置IP地址
		NETMASK=255.255.255.0	//设置子网掩码
		GATEWAY=192.168.10.254	//设置网关
nmcli device connect ens33 //连接ens33网卡
ip address	//查看网卡信息
	 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
	    link/ether 00:0c:29:3b:9b:d6 brd ff:ff:ff:ff:ff:ff
	    inet 192.168.10.102/24 brd 192.168.10.255 scope global noprefixroute ens33
	       valid_lft forever preferred_lft forever
	    inet6 fe80::d2ca:c39f:5d8c:570d/64 scope link noprefixroute 
	       valid_lft forever preferred_lft forever

2.安装httpd服务

yum -y install httpd		//安装http服务
systemctl start httpd		//开启http服务
systemctl enable httpd		//开机自启服务
firewall-cmd --add-port=80/tcp --permanent		//防火墙添加允许条目

现在可以访问默认http网页了
在这里插入图片描述
可以在/var/www/html/下添加网页文件使其可以访问

cd /var/www/html/
vi index.html
	this is test page
cat index.html
this is test page

再次访问
在这里插入图片描述
另外自己需要建立站点的话直接在/etc/httpd/conf.d/写.cnf后缀名的文件

cd /etc/httpd/conf.d/
vim virtual.conf
	<virtualhost *:8080>
        documentroot /web/	
        servername www.test.com
	</virtualhost>
	<directory /web>		#由于修改了默认存放目录,所以需要加入这些配置
    	AllowOverride None
    	Require all granted
	</directory>
[root@localhost ~]# mkdir /web
cd /web
vi index.html
cat index.html
	this is test page 2
vi /etc/httpd/conf/httpd.conf	#在主配置文件中插入8080端口的监听
	listen 8080	
firewall-cmd --add-port=8080/tcp --permanent	#防火墙放行
systemctl restart httpd

由于域名不是正规域名,需要搭建DNS服务器,所以我只修改了windows下的hosts文件
在这里插入图片描述
以上就做完了,现在创建apache网页认证

vi /etc/httpd/conf.d/auth.conf
	<virtualhost *:1234>
        documentroot /auth
        servername www.auth.com
</virtualhost>
<directory /auth>
        allowoverride all
        authtype basic
        authname "password"
        authuserfile "/auth/authfile"
		require valid-user	
</directory>
htpasswd -c /auth/authfile zhangsan		#设置网页用户密码第一次需要加-c
htpasswd  /auth/authfile wangwu			#设置网页用户密码
firewall-cmd --add-port=1234/tcp --permanent	#防火墙放行规则
systemctl restart httpd		#重启服务 

在这里插入图片描述
在这里插入图片描述

HTTPS

为了方便,这里我使用的是自签证书

yum -y install mod_ssl openssl-devel
openssl genrsa -out https.key 2048
openssl req -new -x509 -key https.key -out https.crt
ls
	https.key	https.crt
vi /etc/http/conf.d/virtualhost.conf
		<virtualhost *:8080>
			documentroot /web
			servername www.test.com
			sslengine on
			SSLProtocol all -SSLv2 -SSLv3
			sslcertificatefile	/root/https.crt
			sslcertificatekeyfile /root/https.key
		</virtualhost>
		<directory /web>
	    	AllowOverride None
	    	Require all granted	
		</directory>
systemctl restart httpd

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值