【CentOS8】常用的Apache(httpd)命令
CentOS8的初始设置命令。
当IP地址或MAC地址发生变更时,请通过以下命令进行更改。
vim /etc/sysconfig/network-scripts/ifcfg-eth0 //編集
cat /etc/sysconfig/network-scripts/ifcfg-eth0 //確認
确认版本
cat /etc/redhat-release
更新
dnf update
DNS服务器设置命令
nmcli connection modify ens192 ipv4.dns 8.8.8.8 //DNS serverアドレス設定
CentOS 支持终止对策
安装Apache的命令
mount /dev/cdrom /media //マウント
dnf install --disablerepo=\* --enablerepo=InstallMedia-* -y httpd httpd-tools httpd-devel httpd-manual //インストールコマンド
经常使用的Apache命令
启动Apache、检查其运行状况和停止运行
sudo systemctl start httpd.service //起動
systemctl status httpd.service //動作確認
sudo systemctl stop httpd.service //停止
重启Apache
service httpd restart
Apache 自动启动
sudo systemctl enable httpd.service //有効
systemctl is-enabled httpd.service //設定確認
sudo systemctl disable httpd.service //無効
如果没有显示任何内容,可能是CentOS的防火墙正在运行。
防火墙设置
防火墙
systemctl stop firewalld //停止
systemctl start firewalld //起動
firewall-cmd --reload //再起動
防火墙自动启动
systemctl enable firewalld //有効
systemctl disable firewalld //無効
防火墙新增通信许可
firewall-cmd --add-port=80/tcp --permanent //http
firewall-cmd --add-port=443/tcp --permanent //https
防火墙重新加载
firewall-cmd --reload
防火墙确认
firewall-cmd --list-all
安装telnet功能
sudo dnf -y install telnet
sudo dnf -y install telnet-server
自動啟動 Telnet
systemctl enable telnet.socket
启动Telnet服务
systemctl start telnet.socket
設定 Chrony
将CentOS8中的ntp更改为chrony。
vim /etc/chrony.conf
#pool 2.centos.pool.ntp.org iburst //変更前
#pool ntp.jst.mfeed.ad.jp iburst //変更後
设定反映
chronyc sources
自動啟動設定的chrony
systemctl enable chronyd
添加 EPEL, Remi 仓库
为了更新软件包,请在CentOS8上添加EPEL和Remi仓库。
dnf install epel-release //EPELリポジトリのインストール
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm //Remiリポジトリのインストール
禁用存储库
dnf repolist //リポジトリ確認
dnf config-manager --disable epel epel-modular remi-modular remi-safe //EPEL、Remiのリポジトリを無効化する
从禁用的存储库中安装软件包的方法。
dnf --enablerepo=epel,remi-safe repolist //無効化リポジトリのいくつかを有効化、複数のリポジトリを指定するときはカンマで区切ります
dnf -y install mod_ssl
配置Apache
apache用户验证 //添加基本验证
mkdir -p /var/www/html/member
htpasswd -c /etc/httpd/.htpasswd secret
//usernameがsecretになる
//初めてファイルを作成する場合は-cをつける
New password:root123
Re-type new password:root123 //パスワードは2回入力
添加认证用户
htpasswd /etc/httpd/.htpasswd 追加するユーザ名
例 htpasswd /etc/httpd/.htpasswd secret2
在 httpd.conf 文件中添加配置
<Directory "/var/www/html/member">
AuthType Basic //認証の種類
AuthName "Secret Zone" //ダイアログにメッセージを表示する名前
AuthUserFile /etc/httpd/.htpasswd //パスワードファイル
Require user secret //認証するユーザ //#Require valid-userでパスワードファイルに記述された全ユーザが対象となる
</Directory>
重启Apache。
service httpd restart
饼干功能新增
在httpd.conf中添加以下内容以添加cookie功能。
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure //HttpOnly属性の有効化
ExpiresActive on //Expiresヘッダの生成を有効にする
ExpiresDefault "access plus 1 hours" //個別に指定しなければ、有効期限は1時間後になる
SSL通信配置
添加模块以进行SSL通信
/etc/httpd/modules/ //モジュールが格納されているディレクトリ
检查是否已经加载了 mod_so.c。
cd /etc/httpd/modules/
ls -a
编译 mod_ssl.c 文件
/etc/httpd/modules/apxs -c -i -a mod_ssl.c
需要在httpd.conf文件中添加以下内容。(如果使用apxs命令来安装,则会自动在httpd.conf文件中添加配置。如果没有添加,则需要手动添加。)
LoadModule rewrite_module modules/mod_rewrite.so
Apache模块设置
启用mod_info模块
LoadModule isapi_module modules/mod_isapi.so //httpd.confに追記
mod_status 模块的设置
Include conf.modules.d/httpd-info.conf //httpd.confに追記
※設定はhttpd.confファイルではなくhttpd-info.confファイルで行います。
デフォルトではhttpd.confからhttpd-info.confを読み込んでいませんので、
最初に読み込むように変更します。
将文件夹 ./usr/share/doc/httpd/ 中的内容移动到 ./etc/httpd/conf.modules.d/ 中。
请确认模块是否已启用。
httpd -M
根据需要
service httpd restart
systemctl reload httpd.service
service httpd configtest //congigureテスト
httpd -l //apacheに組み込まれているモジュールの確認