実験環境はredhat7.0システムであり、すべての実験「は、そのような研究の面でのlinux」からのもの
、Apacheのプログラムは、現在のクロスプラットフォームおよびセキュリティでかつ迅速に認識されているWebサービスプログラムの高い市場シェアを持っています見事な戦術と無限の忍耐と意味のアメリカインディアンの先住民族の言語からの信頼性の高い、シンプルなAPIの拡張名、。
インストール
[root@localhost ~]# yum install httpd -y
場所プロファイル
サービスカタログ | の/ etc / httpdの |
---|---|
メインの設定ファイル | ある/etc/httpd/conf/httpd.conf |
サイトのデータディレクトリ | / var / www / htmlと設定 |
アクセスログ | / var / log / httpdの/ access_logの |
エラーログ | / var / log / httpdの/ error_logに |
ServerRootディレクトリサービス
SERVERADMIN管理者のメールボックスの
ユーザーには、サービス利用者の実行
サービスのユーザーグループを実行するには、グループ
のドメインネームサーバのServerNameウェブサイト
のDocumentRootサイトのデータディレクトリを
IPアドレスとポート番号リスニング聞く
のDirectoryIndexのデフォルトインデックスページページ
のErrorLogエラー・ログ・ファイル
のCustomLogアクセスログファイル
のタイムアウトをページのタイムアウト、デフォルトは300秒です
1.カスタムウェブサイト
サイトディレクトリを作成するには、1.1
[root@localhost ~]# mkdir /home/wwwroot
[root@localhost ~]# echo " This is my web" >/home/wwwroot/index.html
SELinuxの設定1.2
セットselinxセキュリティコンテキスト
# 查看httpd默认网站目录的值
[root@localhost ~]# ls -ldZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
# 将新建的网站目录设置相同的安全上下文值
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/*
# 重新加载生效
[root@localhost ~]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
semanagerコマンドSELinuxの経営戦略、 "semanager [オプション] [ファイル]"
-lクエリ
-a追加
、変更するには、-m
-d [削除]を
1.3設定ファイルを変更します
119 DocumentRoot "/home/wwwroot"
120
121 #
122 # Relax access to content within /var/www.
123 #
124 <Directory "/home/wwwroot">
125 AllowOverride None
126 # Allow open access:
127 Require all granted
128 </Directory>
1.4サービスの起動
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 设置防火墙
[root@localhost ~]# firewall-cmd --permanent --add-service=http
success
[root@localhost ~]# firewall-cmd --permanent --add-service=https
success
[root@localhost ~]# firewall-cmd --reload
success
データ・ページのWebディレクトリかどうかをテストへのアクセス、あなたが訪問することができない場合は、ファイアウォールをチェックし、SELinuxの、
2.個々のユーザのホーム機能
システム内のすべてのユーザーが自分のホームディレクトリに個人的なウェブサイトを管理するように、プロファイル機能httpdサービスプログラムを提供することができます。
2.1ホームがオープン個々のユーザーが特徴
ライン(オープンユーザのホーム・ページ)うち17コメントは、コメントは24行(ユーザーのホームディレクトリのウェブサイトで保存された位置データを)削除されます。
[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
15 # permissions).
16 #
17 #UserDir disabled
18
19 #
20 # To enable requests to /~user/ to serve the user's public_html
21 # directory, remove the "UserDir disabled" line above, and uncomment
22 # the following line instead:
23 #
24 UserDir public_html
25 </IfModule>
26
2.2ユーザーの作成
ユーザーを作成し、権限を設定し、他の人々はまた、ディレクトリの内容を読み取るためのアクセス許可を持っていることを確認してください
[root@localhost ~]# useradd developer
[root@localhost ~]# su - developer
[developer@localhost ~]$ mkdir public_html
[developer@localhost ~]$ echo "this is developer's home" >public_html/index.html
[developer@localhost ~]$ chmod -fR 755 /home/developer
SELinuxの設定2.3
ユーザーのデータディレクトリサイトのホームディレクトリ自体は、それほどのSELinuxのセキュリティコンテキストのホームディレクトリを変更しないでください。セキュリティポリシーのHTTP SELinuxのビューに関連付けられている使用getseboolドメイン名
[root@localhost ~]# getsebool -a |grep httpd
httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off
# 开启 httpd_enable_homedir
[root@localhost ~]# setsebool -P httpd_enable_homedirs=on
2.4サービスの起動
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 设置防火墙
[root@localhost ~]# firewall-cmd --permanent --add-service=http
success
[root@localhost ~]# firewall-cmd --permanent --add-service=https
success
[root@localhost ~]# firewall-cmd --reload
success
テストアクセス
2.5認証設定
サイトにアクセスすると、認証されたユーザーのみがために、サイトのコンテンツにアクセスすることができ
まず、htpasswdコマンド音場のパスワードデータベースを使用するユーザーは、htpasswdは-c」の形式が保存されていないパスワードを追加する前に、-c引数を使用する必要性を作成しますファイルのユーザ名」は、ユーザがローカルシステムユーザーである必要はありません。
[root@localhost ~]# htpasswd -c /etc/httpd/passwd user007
New password:
Re-type new password:
Adding password for user user007
設定ファイル、設定パラメータ31-37行を変更します。
[root@localhost ~]# vim /etc/httpd/conf.d/userdir.conf
31 <Directory "/home/*/public_html">
32 AllowOverride all
33 authuserfile "/etc/httpd/passwd"
34 authname "please auth"
35 authtype basic
36 Require user user007
37 </Directory>
httpdの再起動
[root@localhost ~]# systemctl restart httpd
テストアクセスは
、ユーザーuser007 REDHATパスワードを入力します。
3.ホスティング機能
あなたが別のウェブサイトの数を展開し、複数の「仮想サーバー」にサーバーを置くことができ、仮想サイトの機能を使用して、3つの方法があります。
- 異なるIPアドレスを要求
- 別のホストのドメイン名をリクエスト
- 別のリクエストポート
IPアドレスに基づいて3.1
3.1.1追加の2つのIP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
DEVICE=eno16777736
USERCTL=no
IPADDR1=192.168.137.10
PREFIX1=24
IPADDR2=192.168.137.20
FREPIX2=24
GATEWAY=192.168.137.2
DNS1=114.114.114.114
[root@localhost ~]# systemctl restart network
3.1.2サイトのディレクトリを作成します。
、192.168.137.10時間へのアクセスを二つの異なるウェブサイトのディレクトリを作成し、「192.168.137.10」を参照してください; 192.168.137.20アクセス、「192.168.137.20」を参照してください。
[root@localhost ~]# mkdir /home/wwwroot/10 -p
[root@localhost ~]# mkdir /home/wwwroot/20 -p
[root@localhost ~]# echo "192.168.137.10" >/home/wwwroot/10/index.html
[root@localhost ~]# echo "192.168.137.20" >/home/wwwroot/20/index.html
3.1.3設定のselinux
SELinuxのセキュリティのコンテキストを設定します
# 查看默认网站目录的值
[root@localhost ~]# ls -ldZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
# 设置新网站selinux安全上下文的值
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/10/*
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/20/*
# 重新加载生效
[root@localhost ~]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_dir_t:s0
restorecon reset /home/wwwroot/10 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_t:s0
restorecon reset /home/wwwroot/10/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_t:s0
restorecon reset /home/wwwroot/20 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_t:s0
restorecon reset /home/wwwroot/20/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:user_home_t:s0
3.1.4設定ファイルを変更します
内容の最後から二番目の行に追加します。
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
<virtualhost 192.168.137.10>
documentroot "/home/wwwroot/10"
servername www.a.com
<directory "/home/wwwroot/10">
allowoverride none
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.137.20>
documentroot "/home/wwwroot/20"
servername www.b.com
<directory "/home/wwwroot/20">
allowoverride none
require all granted
</directory>
</virtualhost>
3.1.5サービスの開始
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 设置防火墙
[root@localhost ~]# firewall-cmd --permanent --add-service=http
success
[root@localhost ~]# firewall-cmd --permanent --add-service=https
success
[root@localhost ~]# firewall-cmd --reload
success
テストアクセス
3.2ベースのドメイン
3.2.1サイトのディレクトリを作成します。
Www.a.comは、2人のドメイン名を定義し、www.b.com。二つのサイトにディレクトリを作成し、2つのサイトは、データを格納しています
[root@localhost Desktop]# mkdir -p /home/wwwroot/a
[root@localhost Desktop]# mkdir -p /home/wwwroot/b
[root@localhost Desktop]# echo "a web" >/home/wwwroot/a/index.html
[root@localhost Desktop]# echo "b web" >/home/wwwroot/b/index.html
3.2.2設定のselinux
# 查看默认网站目录的值
[root@localhost Desktop]# ls -ldZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
# 设置新网站的selinux安全上下文的值
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/a
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/a/*
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/b
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/b/*
# 重新加载生效
[root@localhost Desktop]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/a context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/a/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/b context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/b/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
3.2.3設定ファイルを変更します
設定ファイルの最後から二番目の行では、以下を追加します
[root@localhost Desktop]# vim /etc/httpd/conf/httpd.conf
<virtualhost 192.168.137.10>
documentroot "/home/wwwroot/a"
servername www.a.com
<directory "/home/wwwroot/a">
allowoverride none
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.137.10>
documentroot "/home/wwwroot/b"
servername www.b.com
<directory "/home/wwwroot/b">
allowoverride none
require all granted
</directory>
</virtualhost>
3.2.4サービスの開始
[root@localhost Desktop]# systemctl restart httpd
[root@localhost Desktop]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 设置防火墙
[root@localhost Desktop]# firewall-cmd --permanent --add-service=http
success
[root@localhost Desktop]# firewall-cmd --permanent --add-service=https
success
[root@localhost Desktop]# firewall-cmd --reload
success
テストクライアントの/ etc / hostsファイルの両方にURLを解析する書き込み
[root@localhost Desktop]# vim /etc/hosts
192.168.137.10 www.a.com www.b.com
3.3ポートに基づいて
3.3.1サイトのディレクトリを作成します。
二つのポート333および222個のポートを定義し、2つのウェブサイトのディレクトリを作成する2つのサイトデータを格納しています
[root@localhost Desktop]# mkdir -p /home/wwwroot/333
[root@localhost Desktop]# mkdir -p /home/wwwroot/222
[root@localhost Desktop]# echo "333 web" >/home/wwwroot/111/index.html
[root@localhost Desktop]# echo "222 web" >/home/wwwroot/222/index.html
3.3.2設定のselinux
サイトディレクトリの値のSELinuxのセキュリティコンテキスト
# 查看默认网站目录的值
[root@localhost Desktop]# ls -ldZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
# 设置新网站的值
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/333
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/333/*
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/222
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot/222/*
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_content_t /home/wwwroot
# 重新加载生效
[root@localhost Desktop]# restorecon -Rv /home/wwwroot/
restorecon reset /home/wwwroot context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/333 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/333/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/222 context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
restorecon reset /home/wwwroot/222/index.html context unconfined_u:object_r:home_root_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0
ポート333および222は、2つのポートがhttpdのを聞くことを可能にする、試験SELinuxのドメインポリシーに追加されました
[root@localhost Desktop]# semanage port -l|grep http
http_cache_port_t tcp 8080, 8118, 8123, 10001-10010
http_cache_port_t udp 3130
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t tcp 5988
pegasus_https_port_t tcp 5989
[root@localhost Desktop]# semanage port -a -t http_port_t -p tcp 222
[root@localhost Desktop]# semanage port -a -t http_port_t -p tcp 333
3.3.3設定ファイルを変更します
[root@localhost wwwroot]# vim /etc/httpd/conf/httpd.conf
listen 222
listen 333
<virtualhost 192.168.137.10:222>
documentroot "/home/wwwroot/222"
servername www.a.com
<directory "/home/wwwroot/222">
allowoverride none
require all granted
</directory>
</virtualhost>
<virtualhost 192.168.137.10:333>
documentroot "/home/wwwroot/333"
servername www.a.com
<directory "/home/wwwroot/333">
allowoverride none
require all granted
</directory>
</virtualhost>
3.3.4サービスの開始
[root@localhost wwwroot]# systemctl restart httpd
[root@localhost wwwroot]# systemctl enable htpd
Failed to issue method call: No such file or directory
[root@localhost wwwroot]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
# 设置防火墙
[root@localhost wwwroot]# firewall-cmd --permanent --add-service=http
success
[root@localhost wwwroot]# firewall-cmd --permanent --add-service=https
success
[root@localhost wwwroot]# firewall-cmd --permanent --add-port=222/tcp
success
[root@localhost wwwroot]# firewall-cmd --permanent --add-port=333/tcp
success
[root@localhost wwwroot]# firewall-cmd --reload
success
テストアクセス