linux——編譯安裝httpd服務,同ip端口,不同域名
阿新 • • 發佈:2018-08-13
tor sbin 檢查 語法 list not src 不同 plist
1.環境,先關防火墻
[root@localhost ~]# systemctl status firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
編譯安裝httpd-2.4
//安裝開發環境 yum groupinstall "Development Tools" yum groups mark install "Development Tools" //安裝檢查 yum grouplist //創建系統用戶,組但不創建新組文件 groupadd -r apache useradd -M -s /sbin/nologin -g apache apache (-M/不自動登陸,-s/這裏指不登陸,-g/指定用戶組) yum -y install openssl-devel pcre-devel expat-devel libtool
//下載並安裝apr-1.4+和apr-util-1.4+ cd /usr/src/ wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2 wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2 //解壓成bz2 tar xf apr-1.6.3.tar.bz2 tar xf apr-util-1.6.1.tar.bz2 //編輯apr-1.6.3配置 cd apr-1.6.3 vim configure cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" //此行加上註釋#或者刪除 //配置過程 ./configure --prefix=/usr/local/apr //編譯安裝過程 make && make install //apr-util-1.6.1配置 cd /usr/src/apr-util-1.6.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr //編譯安裝 make && make install //編譯安裝httpd wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2 [root@localhost ~]# ls httpd-2.4.34.tar.bz2 [root@localhost ~]# tar xf httpd-2.4.34.tar.bz2 [root@localhost ~]# cd httpd-2.4.34 [root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork [root@localhost httpd-2.4.34]# make && make install
註:
./configure --prefix=/usr/local/apache \ //安裝路徑
”--sysconfdir=/etc/httpd24 \ 配置路徑
--with-mpm=prefork 可改成worker
”
虛擬主機
虛擬主機有三類:
- 相同IP不同端口
- 不同IP相同端口
- 相同IP不同端口不同域名
vim /etc/httpd24/httpd.conf
ServerName www.example.com:80 //取消註釋(刪除#) [root@localhost httpd-2.4.34]# vim /etc/httpd24/httpd.conf //進入配置,同ip,不同域名 <VirtualHost 192.168.56.11:80> ServerName www.guohui.com DocumentRoot "/usr/local/apache/htdocs/guohui" ErrorLog "logs/guohui/error_log" CustomLog "logs/guohui/access_log" combined <Directory "/usr/local/apache/htdocs/guohui"> <RequireAll> Require all granted Require not ip 192.168.1 </RequireAll> </Directory> </VirtualHost> <VirtualHost 192.168.56.11:80> ServerName www.guohui1.com DocumentRoot "/usr/local/apache/htdocs/guohui" ErrorLog "logs/guohui/error_log" CustomLog "logs/guohui/access_log" combined <Directory "/usr/local/apache/htdocs/guohui"> <RequireAll> Require all granted Require not ip 192.168.1 </RequireAll> </Directory> </VirtualHost> set nu
創建網址文件
[root@localhost httpd-2.4.34]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir guohui guohui1
[root@localhost guohui]# echo ‘guo‘ > guohui/index.html
[root@localhost guohui]# echo ‘hui‘ > guohui1/index.html
在logs下創建文件
root@localhost ~]# cd /usr/local/apache/logs
[root@localhost logs]# mkdir guohui guohui1
賦予屬主屬組權限
chown -R apache.apache /usr/local/apache/htdocs
chown -R apache.apache /usr/local/apache/logs
[root@localhost htdocs]# cd /usr/local/apache/htdocs
[root@localhost htdocs]# chown -R apache.apache guohui
[root@localhost htdocs]# chown -R apache.apache guohui1
啟動方式
1.
[root@localhost htdocs]# /usr/local/apache/bin/apachectl start 啟動
/usr/local/apache/bin/apachectl gracefu 重啟服務
apachectl -t 檢查
2.
/usr/local/apache/bin/httpd 啟動
/usr/local/apache/bin/httpd -t 檢查語法
/usr/local/apache/bin/apachectl
start
restart
stop
restart
編輯etc/host文件地點,ip+網址
windows C:\Windows\System32\drivers\etc
linux etc/host
curl www.guohui.com 訪問
要清空瀏覽器緩存
-j 4 //4核速度
linux——編譯安裝httpd服務,同ip端口,不同域名