linux——apache
生活随笔
收集整理的這篇文章主要介紹了
linux——apache
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Apache
Apache是世界上使用排名第一的Web服務(wù)器軟件,它可以運(yùn)行在所有廣泛使用的計(jì)算機(jī)平臺(tái)上,由于其跨平臺(tái)和安全性被廣泛使用,是最流行的Web服務(wù)器端軟件之一。
一、Apache的前期準(zhǔn)備
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# netstat -antlupe | grep 80
tcp6 0 0 :::80 :::* LISTEN 0 36254 2133/httpd
[root@localhost ~]# netstat -antlupe | grep httpd
tcp6 0 0 :::80 :::* LISTEN 0 36254 2133/httpd
[root@localhost ~]# cd /var/www/html/ ? ? ##目錄/var/www/html是默認(rèn)訪問(wèn)目錄
[root@localhost html]# systemctl stop firewalld
[root@localhost html]# vim index.html ? ? ##index.html文件是默認(rèn)訪問(wèn)文件
[root@localhost html]# cat index.html
<h1>/var/www/html/index's page<h1> ? ? ? ?##<h1>內(nèi)容<h1> 這是html的寫法,表示的格式是標(biāo)題一
[root@localhost html]# vim tutu.html ? ? ?##tutu.html不是默認(rèn)訪問(wèn)文件,所以在訪問(wèn)時(shí),需訪問(wèn)http://ip/tutu.html
[root@localhost html]# cat tutu.html
<h1>/var/www/html/tutu's page<h1>
[root@localhost html]#
瀏覽器查看——http://172.25.254.127/
瀏覽器查看——http://172.25.254.127/tutu.html
二、Apache的基本配置
1、協(xié)議端口的修改
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ? ? ##httpd的配置文件 Listen 80 ——> Listen 8080 ##修改第42行 [root@localhost html]# systemctl restart httpd [root@localhost html]# netstat -antlupe | grep httpd tcp6 0 0 :::8080 :::* LISTEN 0 110156 9396/httpd瀏覽器訪問(wèn)——http://172.25.254.127
[root@localhost html]# vim /etc/httpd/conf/httpd.conf Listen 8080 ——> Listen 80 ? ?##修改第42行 [root@localhost html]# systemctl restart httpd [root@localhost html]# netstat -antlupe | grep httpd tcp6 0 0 :::80 :::* LISTEN 0 111224 9449/httpd
瀏覽器訪問(wèn)——http://172.25.254.127
2、默認(rèn)訪問(wèn)目錄、文件的設(shè)置
[root@localhost html]# pwd /var/www/html [root@localhost html]# mkdir /westos/html -p [root@localhost html]# cd /westos/html/ [root@localhost html]# pwd /westos/html [root@localhost html]# vim index.html [root@localhost html]# cat index.html <h1>/westos/html/index's page</h1>瀏覽器訪問(wèn)——http://172.25.254.127
瀏覽器訪問(wèn)——http://172.25.254.127(默認(rèn)目錄)
[root@localhost html]# ls index.html [root@localhost html]# vim test.html [root@localhost html]# cat test.html <h1>/westos/html/test's page</h1> [root@localhost html]# vim /etc/httpd/conf/httpd.conf ? ?##添加第123行,設(shè)置默認(rèn)訪問(wèn)文件為test.html 120 DocumentRoot "/westos/html" 121 <Directory "/westos"> 122 require all granted 123 DirectoryIndex test.html 124 </Directory> [root@localhost html]# systemctl restart httpd
瀏覽器訪問(wèn)——http://172.25.254.127(默認(rèn)文件)
瀏覽器訪問(wèn)——http://172.25.254.127/linux
3、基于ip的身份認(rèn)證
[root@localhost html]# vim /etc/httpd/conf/httpd.conf ##恢復(fù)原配置,即刪除120——127行或者注釋掉,這里是刪除了 [root@localhost html]# systemctl restart httpd [root@localhost html]# pwd /westos/html [root@localhost html]# cd /var/www/html/ [root@localhost html]# ls index.html tutu.html [root@localhost html]# mkdir westos [root@localhost html]# ls index.html tutu.html westos [root@localhost html]# cd westos/ [root@localhost westos]# ls [root@localhost westos]# vim index.html [root@localhost westos]# cat index.html <h1>/var/www/html/westos/index's page</h1> [root@localhost westos]# vim /etc/httpd/conf/httpd.conf ? ? ##添加第120——124行,相當(dāng)于黑名單 ##效果:除了ip為172.25.254.50的不能訪問(wèn)外,其他ip都可以訪問(wèn) 119 DocumentRoot "/var/www/html" 120 <Directory "/var/www/html/westos"> 121 Order Allow,Deny ? ? ? ?##先讀Allow,再讀Deny 122 Allow from All ? ? ? ??##允許所有ip訪問(wèn) 123 Deny from 172.25.254.50 ? ##禁止172.25.254.50訪問(wèn) 124 </Directory> [root@localhost westos]# systemctl restart httpdip為172.25.254.127的主機(jī)進(jìn)行訪問(wèn)
ip為172.25.254.50的主機(jī)進(jìn)行訪問(wèn)
ip為172.25.254.127的主機(jī)進(jìn)行訪問(wèn)
ip為172.25.254.50的主機(jī)進(jìn)行訪問(wèn)
4、基于用戶的身份認(rèn)證
- 登陸成功后
- 因?yàn)橹辉试S用戶admin登陸,所以用戶tom登陸時(shí),不能成功,會(huì)再次回到登陸頁(yè)面
三、關(guān)于節(jié)點(diǎn)設(shè)置以及HTTPS加密的設(shè)置
1、Apache——一臺(tái)主機(jī)設(shè)置多個(gè)節(jié)點(diǎn)
測(cè)試主機(jī)設(shè)置(使用瀏覽器進(jìn)行訪問(wèn)的主機(jī))
Apache主機(jī)設(shè)置
訪問(wèn)——www.westos.com
訪問(wèn)——news.westos.com
訪問(wèn)——music.westos.com
2、HTTPS配置
[root@localhost ~]# yum install mod_ssl -y
[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ls /etc/httpd/conf.d/
autoindex.conf music.conf README userdir.conf
default.conf news.conf ssl.conf welcome.conf
[root@localhost conf.d]# systemctl restart httpd
##訪問(wèn)https://www.westos.com,下載證書,但是證書不是自己的信息,如下圖
##上面這張圖加載時(shí),需要在輸入字符(隨意輸入),不然無(wú)法完成加載
[root@localhost conf.d]# vim ssl.conf 101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt 108 SSLCertificateFile /etc/pki/tls/private/www.westos.com.key [root@localhost conf.d]# systemctl restart httpd ##訪問(wèn)https://www.westos.com,下載證書,現(xiàn)在證書才是自己的信息 ##每次訪問(wèn)HTTPS時(shí),都必須訪問(wèn)https://域名3、輸入域名跳轉(zhuǎn),自動(dòng)成為HTTPS
[root@localhost conf.d]# ls
autoindex.conf music.conf README tmprequest welcome.conf
default.conf news.conf ssl.conf userdir.conf
[root@localhost conf.d]# vim login.conf
[root@localhost conf.d]# cat login.conf
<VirtualHost *:443>ServerName login.westos.comDocumentRoot "/var/www/virtual/westos.com/login/"CustomLog "logs/login.log" combinedSSLEngine onSSLCertificateFile /etc/pki/tls/certs/www.westos.com.crtSSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
<Directory "/var/www/virtual/westos.com/login/">Require all granted
</Directory>
<VirtualHost *:80>ServerName login.westos.comRewriteEngine onRewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
[root@localhost conf.d]# mkdir -p /var/www/virtual/westos.com/login/
[root@localhost conf.d]# vim /var/www/virtual/westos.com/login/index.html
[root@localhost conf.d]# cat /var/www/virtual/westos.com/login/index.html
<h1>/var/www/virtual/westos.com/login/index's page<h1>
[root@localhost conf.d]# systemctl restart httpd
##輸入配置過(guò)的域名時(shí),會(huì)自動(dòng)跳轉(zhuǎn)成為HTTPS,這里是配置的是www.westos.com,此處就不附測(cè)試的圖了,第一次訪問(wèn),需要下載證書
四、集成PHP 和 CGI
[root@localhost conf.d]# yum install httpd-manual -y ? ?##安裝此軟件,可以訪問(wèn)ip/manual——php等的說(shuō)明 [root@localhost conf.d]# systemctl restart httpdPHP
CGI
五、論壇的搭建
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
cgi Discuz_X3.2_SC_UTF8.zip index.html index.php tutu.html westos
##Discuz_X3.2_SC_UTF8.zip——從網(wǎng)上下載,或者從其他處獲取
[root@localhost html]# unzip Discuz_X3.2_SC_UTF8.zip
[root@localhost html]# ls
cgi index.html readme upload westos
Discuz_X3.2_SC_UTF8.zip index.php tutu.html utility
[root@localhost html]# chmod 777 /var/www/html/upload/ -R
[root@localhost html]# php -m
##參數(shù): -m Show compiled in modules
【root@localhost html]# yum install php-mysql.x86_64 -y
[root@localhost html]# systemctl restart httpd
六、代理上網(wǎng)(翻墻)
可以上網(wǎng)的主機(jī)設(shè)置
不能上網(wǎng)的主機(jī)設(shè)置代理
七、squid+apache實(shí)現(xiàn)緩存加速
IP為172.25.254.50的設(shè)置——Apache(距離較遠(yuǎn))
IP為172.25.254.227的設(shè)置——Squid(距離較近)
總結(jié)
以上是生活随笔為你收集整理的linux——apache的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux——数据库mariadb的基础
- 下一篇: linux——samba共享以及基础用法