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

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/261828.html
標籤:其他
上一篇:Linux常用shell命令總結
