日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux——apache

發(fā)布時(shí)間:2025/3/19 linux 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

[root@localhost html]# vim /etc/httpd/conf/httpd.conf ? ? ?##注釋掉第119行,添加120——123行內(nèi)容如下 119 #DocumentRoot "/var/www/html" ? ? ? ? ? 120 DocumentRoot "/westos/html" 121 <Directory "/westos"> 122 require all granted 123 </Directory> [root@localhost html]# systemctl restart httpd
  • 瀏覽器訪問(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)文件)
[root@localhost html]# pwd /westos/html [root@localhost html]# ls index.html test.html [root@localhost html]# mkdir linux [root@localhost html]# cd linux/ [root@localhost linux]# vim index.html [root@localhost linux]# cat index.html <h1>/westos/html/linux/index's page<h1> [root@localhost linux]# vim test.html [root@localhost linux]# cat test.html <h1>/westos/html/linux/test's page<h1>
  • 瀏覽器訪問(wèn)——http://172.25.254.127/linux

[root@localhost linux]# vim /etc/httpd/conf/httpd.conf ? ?##添加121——123行,使得訪問(wèn)linux目錄時(shí),默認(rèn)文件是index.html 120 DocumentRoot "/westos/html" 121 <Directory "/westos/html/linux"> 122 DirectoryIndex index.html 123 </Directory> 124 <Directory "/westos"> 125 require all granted 126 DirectoryIndex test.html 127 </Directory> [root@localhost linux]# systemctl restart httpd

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 httpd
  • ip為172.25.254.127的主機(jī)進(jìn)行訪問(wèn)

  • ip為172.25.254.50的主機(jī)進(jìn)行訪問(wèn)


[root@localhost ~]# vim /etc/httpd/conf/httpd.conf ##修改第120——125行,相當(dāng)于白名單 ##效果:除了ip為172.25.254.50的不能訪問(wèn)外,其他ip都可以訪問(wèn) 119 DocumentRoot "/var/www/html" 120 #DocumentRoot "/westos/html" 121 <Directory "/var/www/html/westos"> 122 Order Deny,Allow ? ? ?##先讀Deny,再讀Allow 123 Allow from 172.25.254.27 ##允許172.25.254.50訪問(wèn) 124 Deny from All ? ? ? ? ?? ##禁止所有ip訪問(wèn) 125 </Directory> [root@localhost ~]# systemctl restart httpd
  • ip為172.25.254.127的主機(jī)進(jìn)行訪問(wèn)


  • ip為172.25.254.50的主機(jī)進(jìn)行訪問(wèn)

  • 4、基于用戶的身份認(rèn)證

[root@localhost westos]# cd /etc/httpd/ [root@localhost httpd]# ls conf conf.d conf.modules.d logs modules run [root@localhost httpd]# htpasswd -cm apacheuser admin ##htpasswd [-cimBdpsDv] [-C cost] passwordfile username ##-c? Create a new file. ##-m? Force MD5 encryption of the password (default). ##添加第二個(gè)用戶時(shí),不要加上“-cNew password: Re-type new password: Adding password for user admin [root@localhost httpd]# cat apacheuser admin:$apr1$.g7wvziV$0TpPETAiCBx5Gzfh5n50G/ [root@localhost httpd]# htpasswd -cm apacheuser tom New password: Re-type new password: Adding password for user tom [root@localhost httpd]# cat apacheuser tom:$apr1$2faTciFK$iHsm6EAb1.SHdkHFL5ur6. [root@localhost httpd]# htpasswd -m apacheuser admin New password: Re-type new password: Adding password for user admin [root@localhost httpd]# cat apacheuser tom:$apr1$2faTciFK$iHsm6EAb1.SHdkHFL5ur6. admin:$apr1$AbU8gYqU$KluSOrkvCLjvSj3QwfRIq/ [root@localhost httpd]# vim /etc/httpd/conf/httpd.conf ##效果:允許/etc/httpd/apacheuser中的用戶admin輸入密碼訪問(wèn),不允許/etc/httpd/apacheuser中的其他用戶訪問(wèn) 119 DocumentRoot "/var/www/html" 120 <Directory "/var/www/html/westos"> 121 AuthUserFile /etc/httpd/apacheuser 122 AuthName "Please input user and password !!" 123 AuthType basic 124 Require user admin 125 </Directory> [root@localhost httpd]# systemctl restart httpd

  • 登陸成功后

  • 因?yàn)橹辉试S用戶admin登陸,所以用戶tom登陸時(shí),不能成功,會(huì)再次回到登陸頁(yè)面

[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf ##效果:允許/etc/httpd/apacheuser中的所有用戶輸入密碼訪問(wèn)(此處就不再進(jìn)行瀏覽器訪問(wèn)測(cè)試了,這就留給你吧,^_^) 119 DocumentRoot "/var/www/html" 120 <Directory "/var/www/html/westos"> 121 AuthUserFile /etc/httpd/apacheuser 122 AuthName "Please input user and password !!" 123 AuthType basic 124 # Require user admin ##注釋掉 125 Require valid-user 126 </Directory> [root@localhost httpd]# systemctl restart httpd

三、關(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ī))
[root@foundation50 Desktop]# vim /etc/hosts 172.25.254.127 www.westos.com news.westos.com music.westos.com login.westos.com [root@foundation50 Desktop]#
  • Apache主機(jī)設(shè)置
[root@localhost httpd]# pwd /etc/httpd [root@localhost httpd]# ls apacheuser conf conf.d conf.modules.d logs modules run [root@localhost httpd]# cd conf.d/ [root@localhost conf.d]# ls autoindex.conf README userdir.conf welcome.conf [root@localhost conf.d]# vim default.conf [root@localhost conf.d]# cat default.conf <VirtualHost _default_:80>DocumentRoot /var/www/htmlCustomLog "logs/default.log" combined </VirtualHost> [root@localhost conf.d]# mkdir /var/www/virtual/westos.com/news -p [root@localhost conf.d]# mkdir /var/www/virtual/westos.com/music -p [root@localhost conf.d]# vim /var/www/virtual/westos.com/news/index.html [root@localhost conf.d]# cat /var/www/virtual/westos.com/news/index.html <h1>/var/www/virtual/westos.com/news/index's page<h1> [root@localhost conf.d]# vim /var/www/virtual/westos.com/music/index.html [root@localhost conf.d]# cat /var/www/virtual/westos.com/music/index.html <h1>/var/www/virtual/westos.com/music/index's page<h1> [root@localhost conf.d]# vim news.conf [root@localhost conf.d]# cat news.conf <VirtualHost *:80>ServerName news.westos.comDocumentRoot "/var/www/virtual/westos.com/news/"CustomLog "logs/default.log" combined </VirtualHost> <Directory "/var/www/virtual/westos.com/news/">Require all granted </Directory> [root@localhost conf.d]# cp news.conf music.conf [root@localhost conf.d]# vim music.conf [root@localhost conf.d]# cat music.conf <VirtualHost *:80>ServerName music.westos.comDocumentRoot "/var/www/virtual/westos.com/music/"CustomLog "logs/default.log" combined </VirtualHost> <Directory "/var/www/virtual/westos.com/music/">Require all granted </Directory> [root@localhost conf.d]# systemctl restart httpd
  • 訪問(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,下載證書,但是證書不是自己的信息,如下圖


[root@localhost conf.d]# yum install crypto-utils -y [root@localhost conf.d]# genkey www.westos.com ##操作見(jiàn)下圖 output will be written to /etc/pki/tls/certs/www.westos.com.crt output key written to /etc/pki/tls/private/www.westos.com.key

##上面這張圖加載時(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 httpd

  • PHP

[root@localhost conf.d]# cd /var/www/html/ [root@localhost html]# ls index.html tutu.html westos [root@localhost html]# vim index.php [root@localhost html]# cat index.php <?phpphpinfo(); ?> [root@localhost html]# yum install php -y [root@localhost html]# vim /etc/httpd/conf/httpd.conf 169 <IfModule dir_module> 170 DirectoryIndex index.php index.html 171 </IfModule> [root@localhost html]# systemctl restart httpd ##瀏覽器訪問(wèn)172.25.254.127

  • CGI

[root@localhost html]# pwd /var/www/html [root@localhost html]# mkdir cgi [root@localhost html]# ls cgi index.html index.php tutu.html westos [root@localhost html]# vim cgi/index.cgi [root@localhost html]# cat cgi/index.cgi #!/usr/bin/perl print "Content-type: text/html\n\n"; print `date`; [root@localhost html]# chmod +x cgi/index.cgi [root@localhost html]# ./cgi/index.cgi Content-type: text/htmlWed May 30 08:14:48 EDT 2018 [root@localhost html]# ./cgi/index.cgi Content-type: text/htmlWed May 30 08:14:57 EDT 2018 ##瀏覽器訪問(wèn)效果,看見(jiàn)/var/www/html/cgi/index.cgi中的文本內(nèi)容如下: #!/usr/bin/perl print "Content-type: text/html\n\n"; print `date`;

[root@localhost html]# ls cgi index.html index.php tutu.html westos [root@localhost html]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# ls autoindex.conf login.conf music.conf php.conf ssl.conf userdir.conf default.conf manual.conf news.conf README tmprequest welcome.conf [root@localhost conf.d]# vim default.conf [root@localhost conf.d]# cat default.conf | tail -n 5 <Directory "/var/www/html/cgi">Options +ExecCGIAddHandler cgi-script .cgiDirectoryIndex index.cgi </Directory> [root@localhost conf.d]# systemctl restart httpd ##瀏覽器訪問(wèn)效果,效果如下: Wed May 30 08:19:21 EDT 2018

五、論壇的搭建

[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è)置

[root@localhost ~]# yum install squid -y [root@localhost ~]# vim /etc/squid/squid.conf 56 http_access allow all 62 cache_dir ufs /var/spool/squid 100 16 256 [root@localhost ~]# systemctl start squid
  • 不能上網(wǎng)的主機(jī)設(shè)置代理



七、squid+apache實(shí)現(xiàn)緩存加速

  • IP為172.25.254.50的設(shè)置——Apache(距離較遠(yuǎn))

[root@shenzhen squid]# yum install squid -y [root@shenzhen squid]# systemctl start squid [root@shenzhen squid]# cd /usr/share/doc/squid-3.3.8/ [root@shenzhen squid-3.3.8]# ls ChangeLog COPYRIGHT README rredir.pl url-normalizer.pl COPYING QUICKSTART rredir.c squid.conf.documented user-agents.pl [root@shenzhen squid]# systemctl stop firewalld [root@shenzhen squid]# cd /var/www/html/ [root@shenzhen html]# vim index.html [root@shenzhen html]# cat index.html <h1>172.25.254.50<h1> [root@shenzhen squid-3.3.8]# systemctl start httpd
  • IP為172.25.254.227的設(shè)置——Squid(距離較近)

[root@xian ~]# yum install squid -y [root@xian ~]# vim /etc/squid/squid.conf56 http_access allow all59 http_port 80 vhost vport60 cache_peer 172.25.254.50 parent 80 0 proxy-only62 cache_dir ufs /var/spool/squid 100 16 256 [root@xian ~]# systemctl start squid [root@xian ~]# systemctl stop firewalld

總結(jié)

以上是生活随笔為你收集整理的linux——apache的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。