apache httpd 站點搭建
※·[root@www ~]# yum install httpd.x86_64 1
1.重啟service httpd restart 時 ,有兩個模塊無法加載 6
§·httpd程序包使用yum安裝
※·[root@www ~]# yum install httpd.x86_64
學習階段先使用yum程序包安裝httpd程序。
[root@www ~]# rpm -qa | grep http httpd-devel-2.2.15-53.el6.centos.x86_64 httpd-tools-2.2.15-53.el6.centos.x86_64 httpd-2.2.15-53.el6.centos.x86_64 [root@www ~]#
查看安裝后生成的文件
[root@www ~]# rpm -ql httpd-2.2.15-53.el6.centos.x86_64 /etc/httpd /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/welcome.conf /etc/httpd/conf/httpd.conf /etc/httpd/conf/magic /etc/httpd/logs /etc/httpd/modules /etc/httpd/run /etc/logrotate.d/httpd /etc/rc.d/init.d/htcacheclean /etc/rc.d/init.d/httpd /etc/sysconfig/htcacheclean /etc/sysconfig/httpd /usr/lib64/httpd /usr/lib64/httpd/modules /usr/lib64/httpd/modules/mod_actions.so /usr/lib64/httpd/modules/mod_alias.so /usr/lib64/httpd/modules/mod_asis.so /usr/lib64/httpd/modules/mod_auth_basic.so /usr/sbin/apachectl /usr/sbin/htcacheclean /usr/sbin/httpd /usr/sbin/httpd.event /usr/sbin/httpd.worker /usr/sbin/httxt2dbm /usr/sbin/rotatelogs /usr/sbin/suexec /var/cache/mod_proxy /var/lib/dav /var/log/httpd /var/run/httpd /var/www /var/www/cgi-bin /var/www/error
※·關于生成的配置文件簡單介紹:
port: (80/tcp) , ( ssl :443/tcp ) # http監聽的服務器地址為:TCP /80,https為:443 /usr/sbin/httpd (MPM : prefork) #運行程序,服務器默認工作模型為 prefork進程 httpd : root root (master process) #主進程生成子進程屬主為 root httpd : apche apche (worker process) #子進程為 apche /etc/rc.d/init.d/httpd #Centos 6.8上生成的服務腳本 /etc/httpd: #工作根目錄,相當于程序安裝目錄 /etc/httpd/conf: #配置文件目錄 /etc/httpd/conf/httpd.conf : #主配置文件 /etc/httpd/conf.d/*.conf #被主配置文件包含 /etc/httpd/modules: -----> /usr/lib64/httpd/modules #鏈接目錄。模塊目錄,提供各種功能,加密等等 /etc/httpd/logs ----->/var/log/httpd #鏈接目錄 日志存放位置 日志文件兩類:訪問日志:access_log 錯誤日志:err_log /var/www/html : #靜態頁面路徑 /var/www/cgi-bin : #動態頁面路徑
§·http主配置文件介紹
[root@www ~]# grep Section /etc/httpd/conf/httpd.conf ### Section 1: Global Environment ### Section 2: 'Main' server configuration ### Section 3: Virtual Hosts [root@www ~]#
※·主配置文件分為三大部分:
[root@www ~]# grep -n Section /etc/httpd/conf/httpd.conf 33 ### Section 1: Global Environment 246 ### Section 2: 'Main' server configuration 974 ### Section 3: Virtual Hosts
[root@www ~]# 1)Global Environment—全局環境配置,決定Apache服務器的全局參數
2)Main server configuration—中心服務配置,相當于是Apache中的默認Web站點,如果我們的服務器中只有一個站點,那么就只需在這里配置就可以了。
3)Virtual Hosts—虛擬主機,虛擬主機不能與Main Server主服務器共存,當啟用了虛擬主機之后,Main Server就不能使用了。
§·http使用中心主機配置
如果使用默認配置,開啟中心主機的配置很簡單:只需要啟動httpd服務即可,apache默認配置為虛擬主機。
開啟中心主機后幾個比較實用的參數
44 ServerTokens OS #頁面顯示APACHE的版本,默認開啟,建議關閉使用prod 57 ServerRoot "/etc/httpd" #httpd工作主目錄路徑,不建議修改。 76 KeepAlive Off #長鏈接默認關閉 102 <IfModule prefork.c> #關于httpd工作模型prefork的設置 103 StartServers 8 104 MinSpareServers 5 105 MaxSpareServers 20 106 ServerLimit 256 107 MaxClients 256 108 MaxRequestsPerChild 4000 109 </IfModule> 136 Listen 80 #默認監聽的端口號 222 Include conf.d/*.conf #可以包含 /etc/httpd/conf.d/*.conf下所有的配置文件 292 DocumentRoot "/var/www/html" #中心主機的web站點默認網頁文件存放路徑 317 <Directory "/var/www/html"> #定義web站點的目錄權限 331 Options Indexes FollowSymLinks 338 AllowOverride None 343 Order allow,deny 344 Allow from all 345 346 </Directory> 402 DirectoryIndex index.html index.html.var #默認加載的主頁網頁名稱 484 ErrorLog logs/error_log #錯誤日志的存儲路徑 497 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined #日志文件格式 498 LogFormat "%h %l %u %t \"%r\" %>s %b" common 499 LogFormat "%{Referer}i -> %U" referer 500 LogFormat "%{User-agent}i" agent CustomLog logs/access_log combined #訪問日志的存放路徑
§·http使用虛擬主機配置
實用虛擬主機就必須關閉中心主機:
292 DocumentRoot "/var/www/html" #注銷掉此行 990 NameVirtualHost 10.1.16.20:80 #開啟此行,設置正確的監聽地址和端口
設置虛擬主機:
<VirtualHost 10.1.16.20:80> DocumentRoot /www/host1 ServerName www1.test1.com </VirtualHost> <VirtualHost 10.1.16.20:80> DocumentRoot /www/host2 ServerName www.test2.com </VirtualHost> <VirtualHost 10.1.16.20:80> DocumentRoot /www/host3 ServerName www.test3.com </VirtualHost>
§·https站點的搭建
https是調用ssl協議加密站點,https服務器搭建 基于:openssl,所以需要在配置一下操作:
步驟一:安裝ssl模塊
[root@localhost ~]#yum install mod_ssl #安裝ssl模塊 [root@localhost ~]# rpm -ql mod_ssl #查詢生成的文件 /etc/httpd/conf.d/ssl.conf #配置文件 /usr/lib64/httpd/modules/mod_ssl.so #生成模塊文件 /var/cache/mod_ssl #緩存文件 /var/cache/mod_ssl/scache.dir /var/cache/mod_ssl/scache.pag /var/cache/mod_ssl/scache.sem [root@com-server modules]# httpd -M | grep ssl #檢查模塊是否加載 Syntax OK ssl_module (shared) [root@com-server modules]#
步驟二:給web服務器頒發證書
注意:一定注意頒發的主機名 一定是域名的名稱
CA服務器:
cd /etc/pki/CA/ (umask066; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048) openssl req -new -x509 –key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem
web服務器:
(umask 066; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048) 生成證書申請文件 openssl req -new -key /etc/httpd/ssl/httpd.key -days 365 -out /etc/httpd/ssl/httpd.csr ?(b) 將證書請求文件傳輸給CA ?(c) CA簽署證書,并將證書頒發給請求者; openssl ca -in /tmp/httpd.csr–out /etc/pki/CA/certs/httpd.crt -days 365 注意:默認國家,省,公司名稱必須和CA一致
web服務器證書存儲路徑
放置路徑為: /etc/httpd/ssl/
[root@com-server key]# ls httpd.csr(證書文件) httpd.key(私鑰文件)
步驟三.配置web服務器ssl文件
編輯配置文件: /etc/httpd/conf.d/ssl.conf 105 SSLCertificateFile /etc/httpd/ssl/httpd.crt #SSLCertificateFile 指定服務器使用的證書。 112 SSLCertificateKeyFile /etc/httpd/ssl/httpd.key #SSLCertificateKeyFile 指定了服務器私鑰文件。
步驟四.配置web服務器虛擬主機
注意此時的虛擬主機的配置的配置文件還是為:/etc/httpd/conf.d/ssl.conf,與 /etc/httpd/conf/httpd.conf無關
編輯配置文件: /etc/httpd/conf.d/ssl.conf
12 LoadModule ssl_module modules/mod_ssl.so 18 Listen 443 74 <VirtualHost 10.1.16.20:443> 75 DocumentRoot "/www/host1" 76 ServerName www.test1.com:443 78 #DocumentRoot "/var/www/html" 79 #ServerName www.example.com:443 83 ErrorLog logs/ssl_error_log 84 TransferLog logs/ssl_access_log 85 LogLevel warn 106 SSLCertificateFile /etc/httpd/ssl/httpd.crt 113 SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 219 CustomLog logs/ssl_request_log \ 222 </VirtualHost>
§·apache與PHP站點的搭建
[root@com-server ssl]# yum install php.x86_64 #安裝php軟件 [root@com-server ssl]# rpm -ql php.x86_64 #查看生產的文件 /etc/httpd/conf.d/php.conf #查看主配置文件 /usr/lib64/httpd/modules/libphp5.so /var/lib/php/session /var/www/icons/php.gif [root@com-server ssl]#
步驟一:配置web服務器虛擬主機
在網頁目錄下放置PHP文件后,即可正常的使用了!
index.php的內容為: <?php phpinfo(); ?>
§·問題記錄
1.重啟service httpd restart 時 ,有兩個模塊無法加載
以前好用的好好的,重啟httpd后,根據錯誤提示,注釋掉/etc/httpd/conf/httpd.conf中的“LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so”后,htppd啟動正常。
但總覺得很奇怪,是什么原因導致的呢?
[root@test ~]#/etc/init.d/httpd startStarting httpd: httpd: Syntax error on line 161 of /etc/httpd/conf/httpd.conf: Cannot load /etc/httpd/modules/mod_ldap.so into server: /etc/httpd/modules/mod_ldap.so: undefined symbol: apr_ldap_ssl_init
問題解決辦法:
1 . 模塊沒有安裝還是系統無法找到模塊?
[root@com-server include]# find / -name mod_ldap.so /usr/lib64/httpd/modules/mod_ldap.so [root@com-server include]# find / -name mod_authnz_ldap.so /usr/lib64/httpd/modules/mod_authnz_ldap.so [root@com-server include]#
2 . 模塊有表明軟件安裝上了,使用 httpd -V
[root@com-server modules]# httpd -V Server version: Apache/2.2.15 (Unix) Server built: May 11 2016 19:28:33 Server's Module Magic Number: 20051115:25 Server loaded: APR 1.3.9, APR-Util 1.3.9 #版本不對 Compiled using: APR 1.5.3, APR-Util 1.5.3 #版本不對 Architecture: 64-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="run/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="logs/accept.lock" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf" [root@com-server modules]#
3 . 回想一下,以前在本機上編譯安裝過http軟件的。使用完后也沒有刪除,在 /etc/ld.so.conf.d/新建一個文件后綴名為.conf的文件里面寫上需要添加的lib路徑名,每次開機會自動加載,刪除 /etc/ld.so.conf.d/的httpd.conf文件重啟機器。
原創文章,作者:linux_root,如若轉載,請注明出處:http://www.www58058.com/50373