標籤:web伺服器 虛擬機器 設定檔
1、查看當前的系統
uname -r
cat /etc/redhat-release
2、通過rpm 安裝httpd
yum install httpd
a、安裝完成後,參看相應的設定檔。
/etc/httpd/conf/httpd.conf # 主設定檔。
A、修改參數
Listen [IP:]port # 可以出現多次。
ServerName www.njjn.com:80
DoucumentRoot /var/www/html # 文檔主目錄
NameVirtualHost 192.168.10.16:80 # 配置虛擬機器是必須配置的參數,【僅在CentOS 6 可用,CentOS 7 以廢除。】
<Directory "/var/www/html"> # 安全的存取控制。
Options None
AllowOverride None
Order allow,deny
Allow from [all | 192.168 | 192.168.0.0/16]
# 基於主機的存取控制
AuthType basic
AuthName "only for root"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
Require valid-user # 基於使用者的存取控制
</Directory>
B、產生使用者的密碼檔案
htpasswd -c -m -b /etc/httpd/conf.d/.htpasswd redhat redhat
-c : 第一次建立時使用
-b : 通過命令列給密碼
-m : 密碼通過MD5加密。
C、查看當前伺服器載入的模組
ps aux # 查看系統運行在哪個MPM模式下
httpd -l # 查看核心模組
-M # 查看所有的模組
-t # 設定檔語法檢查。
/etc/httpd/conf.d/ # 輔助設定檔。
/etc/sysconfig/httpd # MPM 資訊。
b、添加到開機啟動。
chkconfig --add httpd
chkconfig httpd on
service httpd start
3、通過瀏覽器查看
問題:伺服器端要關閉防火牆和selinux
iptables -F
setenforce 0 | permissive
4、配置虛擬機器主機 【based-name】
a、配置主設定檔裡面的參數。
/etc/httpd/conf/httpd.conf 添加 NameVirtualHost 192.168.10.15:80
b、在/etc/httpd/conf.d/ 目錄裡面建立虛擬和主機的設定檔。
vi vhost-1.conf
<VirtualHost 192.168.10.15:80> # 要和 NameVirtualHost 相同。
ServerName "www.njjn.com"
DocumentRoot "/data/vhosts/www1"
CustomLog "logs/www1-access-log" combined # 相對路徑,相對與 ServerRoot ,設定檔的路徑。 /etc/httpd/logs 是 目錄的軟連連結。
ErrorLog "logs/www1-error-log"
# 如果在CentOS 7上,需要顯示的給予授權。因為它預設是拒絕的。和 6 相反。
<Directory "/data/vhosts/www1"> # 對虛擬主機設定存取控制
Options None
AllowOverride None
Require [not] ip 192.168 # 僅 192.168.0.0 網段的可以訪問。
Require [not] host www.njjn.com # 使用一個就可以。
Require all granted # 所有人都可以訪問
</Directory>
<Location /server-status> # 查看伺服器的運行狀態的資訊。
SetHandler server-status
AuthType basic
AuthName "only for limit user"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
Require valid-user | user1 user2
</Location> # 僅認證過的賬戶可以訪問,
</VirtualHost>
5、配置 https
a、建立私人的CA
cd /etc/pki/CA
(umask 066; openssl genrsa -out private/cakey.pem 2048) # 私密金鑰必須是600許可權,
openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
產生自簽整數。
openssl x509 -in private/cakey.pem -text # 大約是,查看整數資訊。
openssl rsautl -in private/cakey.pem -out capub.pem -pubout
b、給應用程式產生,
(umask 066; openssl genrsa -out httpd.key 1024)
openssl req -new -key httpd.key -out httpd.csr -days 3650
scp httpd.csr [email protected]:/tmp/
d、CA 給予授權
openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 3650
scp 傳給用戶端。
e、用戶端收到後,
mkdir /etc/httpd/ssl
把檔案放到上面的目錄。
f、用戶端安裝,https 需要的 mod_ssl rpm 包
此包會在,/etc/httpd/conf.d/目錄,建立ssl.conf 檔案。
編輯參數。
ServerName
DocumentRoot
SSLCertificateFile "/etc/httpd/ssl/httpd.crt" # 整數檔案, httpd.crt
SSLCertificateKeyFile "/etc/httpd/ssl/httpd.key" # 原生私密金鑰檔案。
重啟服務:service httpd start
通過瀏覽器訪問,要把私人CA的私密金鑰匯入瀏覽器,不然會提示認證無效。不匯入也不影響使用。
6、安裝mysql ,mariadb
yum install mysql-server | mariadb-server
a、配置參數
vi /etc/my.cnf
innodb_file_per_table=ON # 每個表對應一個檔案。
skip_name_resolve=ON # 跳過名稱解析。CentOS 6 【無效】。
7、安裝php, php-zts, php-mysql
yum install php
a、會產生,libphp5.so 庫,可以和 prefork 相匹配。
b、libphp5-zts.so 可以和 worker,event 想匹配,所在包是php-zts
這兩種都是,httpd的模組的形式工作。
Client request index.php -> Server httpd receive, 啟用,php進程,進行處理。
php-mysql : 是為php 和mysql通訊提供驅動。
編輯及頁面,/data/vhosts/www1/index.php
vi ~~
<?php
phpinfo();
?>
客戶成功,鎖屏配置成功。
httpd 2.4: 特性
1、DSO: dynamic share object, 支援動態模組編輯,
2、毫秒級的KeepAlive 500ms 持久串連。
3、MPM event 可以在生產中使用。
4、效能提升,節約記憶體等。
apr: apache portable runtime ,httpd跨平台的基礎。
apr
apr-util
apr-iconv
本文出自 “11650580” 部落格,請務必保留此出處http://11660580.blog.51cto.com/11650580/1826414
CentOS 平台,使用 httpd 2.2 和 httpd 2.4 部署 web伺服器