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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux从入门到精通——Apache

發布時間:2025/3/15 linux 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux从入门到精通——Apache 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

###apache###

企業中常用的web服務,用來提供http:// (超文本傳輸協議)
httpd是apaceh服務器守護的進程


1.apache安裝
?? yum install httpd -y ? ? ? ? ? ? ? ? ##apache軟件的安裝
?? yum install httpd—manual ? ? ?##apache的手冊
?? systemctl start httpd???????
?? systemctl enable httpd???????
?? systemctl start firewalld
?? firewall-cmd --list-all ? ? ·  ? ? ##列出火墻信息
?? firewall-cmd --permanent --add-server=http?? ##永久允許http
?? firewall-cmd --reload ? ? ? ? ? ? ##火墻的重新加載策略
?? netstat -antlupe|grep httpd ? ?##查看監聽端口,默認端口80
??
?? cd /var/www/html ? ? ? ? ? ? ? ? ?##apache的 / 目錄,默認發布目錄
?? vim index.html ? ? ? ? ? ? ? ? ? ? ?##默認發布文件? /var/www/html/index.html
??? <h1> hahahaha wangfang </h1>
      

      

?

?? 測試:
?? 在火狐瀏覽器上輸入 172.25.254.110?? ##會出現 hahahaha wangfang
      

?

?? ls???
?? index.html
?? vim westos
??? <h1> wangfang westos's index.html </h1>?
      

?

????? 在火狐瀏覽器上輸入172.25.254.110/westos??? ##會出現wangfang westos's index.html??
      

?

?? yum install httpd—manual???? ##apache的手冊
?? 測試:
?? 172.25.254.110/manual

2.apache的基礎信息
?? 主配置目錄 /etc/httpd/conf
?? 主配置文件 /etc/httpd/conf/httpd.conf
?? 子配置目錄 /etc/httpd/conf.d/
?? 子配置文件 /etc/httpd/conf.d/*.conf
??
?? 默認發布目錄 /var/www/html
?? 默認發布文件 index.html
?? 默認端口 80
?? 默認安全上下文 httpd_sys_content_t
?? 程序開啟默認用戶 apache
?? apache日志 /etc/httpd/logs/*

?? (1)修改默認端口:
??? vim /etc/httpd/conf/httpd.conf
??? 43 Listen 8080 ? ? ? ? ? ? ? ? ?##修改默認端口為8080
??? firewall-cmd --permanent --add-port=8080/tcp??
??? firewall-cmd --reload
??? netstat -antlupe|grep httpd? ##查看監聽端口,默認端口80
      

      

      

?

?? (2)修改默認發布文件:
??? vim /etc/httpd/conf/httpd.conf???
??? DocumetRoot "/westos/html"??????? ##目錄
??? <Directory "/westos">????????????
??????? Require all granted
??? </Directory>
      

?

??? <IfModule dir_module>???????????? ##文件
??? ?? DirectoryIndex westos index.html
??? </IfModule>
      

?

??? 測試:
??? 172.25.254.110???? ##會出現westos里的內容

3.apache的訪問控制
?? (1)
?? vim /etc/httpd/conf/httpd.conf
?? <Directory "/var/www/html/westos">
??? Order Allow,Deny ? ? ? ? ? ? ? ? ? ?##這里的命令,先讀取allow,后讀取deny
??? Allow from All ? ? ? ? ? ? ? ? ? ? ? ? ?##先允許全部人訪問
??? Deny from 172.25.254.110???? ##再在允許訪問的名單中將110這個ip覆蓋掉
?? </Directory> ? ? ? ? ? ? ? ? ? ? ? ? ? ?##除了110都可以訪問
??
? <Directory "/var/www/html/westos">
??? Order Deny,Allow ? ? ? ? ? ? ? ? ##這里的命令,先讀取deny,后讀取allow
??? Allow from 172.25.254.110???? ##先禁止全部人訪問
??? Deny from all??? ??    ? ? ? ? ?##再在禁止訪問的名單中將110這個ip,設為允許訪問
?? </Directory>????????????  ?? ? ? ? ? ##除了110都不能訪問
      

      

?

?? (2)設定用戶登陸
?? cd /etc/httpd/conf/
?? htpasswd -cm westosuser wf?????? ##建立用戶(會要求設置密碼)
?? htpasswd -m westosuser lsy?????
?? 注意:當有一個用戶存在的時候。就不能用 -cm 來建立新的用戶,如果這樣建立會將原來的用戶覆蓋掉。重新添加用戶應該用 -m 。如果本身沒有用戶存在,則需要用 -cm
      

      

?

?? 創建好用戶后可以用 cat westosuser 這個命令查看
??
?? 在設置好用戶后,就可以設置用戶輸入賬戶和密碼查看:(ps:要將上面的注釋掉)
?? vim /etc/httpd/conf/httpd.conf
?? <Directory "/var/www/html/westos">
??? # Order Allow,Deny????????????
??? # Allow from All???? ????
??? # Deny from 172.25.254.110?
      ??
??? AuthUserFile /etc/httpd/conf/westosuser
??? AuthTYpe basic
??? AuthName "please input your name and passwd !!"
? ? ?#Require user wf ? ? ? ? ? ##只允許wf用戶訪問
? ? Require valid-user???? ##允許所有有效用戶訪問,必須要寫,不寫的話,就沒有密碼驗證的對話框
?? </Directory>??????????????????
?? systemctl restart httpd
      

      

?

?? 測試:
?? 172.25.254.110/westos
      

?

4.apache的虛擬主機(為了訪問不同的頁面)
?? cd /var/www/
?? mkdir -p virtual/news/html
?? mkdir -p virtual/news/html
?? vim /var/www/virtual/news/html/index.html
??? <h1> news's page </h1>

      

?? vim /var/www/virtual/music/html/index.html
??? <h1> music's page </h1>
      

?

?? cd /etc/httpd/conf.d/
?? vim a_default.conf
??? <Virtualhost _default_:80>
??????? DocumentRoot /var/www/html
??????? CustomLog logs/dedfault.log combined
??? </Virtualhost>

?? vim news.conf
??? <VirtualHost *:80>
??????? ServerName news.westos.com
??????? DocumentRoot /var/www/virtual/news/html
??????? CustomLog logs/news.log combined
??? </VirtualHost>

??? <Directory "/var/www/virtual/news/html">
??????? Require all granted
??? </Directory>
      
?? vim music.conf
??? <VirtualHost *:80>
??????? ServerName music.westos.com
??????? DocumentRoot /var/www/virtual/music/html
??????? CustomLog logs/music.log combined
??? </VirtualHost>

??? <Directory "/var/www/virtual/music/html">
??????? Require all granted
??? </Directory>
      

?

?? systemctl restart httpd


?? 測試:
?? vim /etc/hosts?? ##做域名解析
?? 172.25.254.110?? www.westos.com?? news.westos.com?? music.westos.com
      

      

      

      

?

5.php 和 cgi
?? cd /var/www/html/
?? vim index.php
??? <?php
??????? phpinfo();
??? ?>
?? yum install php -y

      

?

? 測試:
?? 172.25.254.110/index.php
      

?

?? cd /var/www/html/
?? mkdir cgi
?? cd cgi/
?? vim index.cgi
??? #!/usr/bin/perl
??? print "Content-type:text/html\n\n";
??? print "Hello,wf.";
?? chmod 755 index.cgi
?? ./index.cgi
      

? ? vim a_dedault.conf
??? <Virtualhost _default_:80>
??????? DocumentRoot /var/www/html
??????? CustomLog logs/dedfault.log combined
??? </Virtualhost>
??? <Directory "/var/www/html/cgi">
??????? Options +ExecCGI
??????? AddHandler cgi-script .cgi
??? </Directory>
      

?

?? 測試:
? ? 172.25.254.110/cgi/index.cgi
      

?

6.apache的簽證

?? yum install mod_ssl -y
?? cd /etc/httpd/conf
?? vim ssl.conf
??? SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ? ? ? ? ? ? ##證書
??? SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key?? ##密鑰
?? systemctl restart httpd
?? yum install crypto-utiles -y
?? genkey www.westos.com?? ????????##獲得證書
?? systemctl restart httpd
      

?

6.網頁重寫(加密訪問) 將 hppt:// 變成 hppts://
?? cd /etc/httpd/conf.d
?? cp ?news.conf ?login.conf
?? vim login.conf
??? <VirtualHost *:80>
??????? ServerName login.westos.com
??????? DocumentRoot /var/www/virtual/login/html
??????? CustomLog logs/login.log combined
??? </VirtualHost>

??? <Directory "/var/www/virtual/login/html">
??????? Require all granted
??? </Directory>

?? vim /var/www/virtual/login/html/index.html
?? <h1> login's page </h1>

?? 測試:
?? 需要手動加 https://

?? vim news.conf
??? <VirtualHost *:443>
??????? ServerName login.westos.com
??????? DocumentRoot /var/www/virtual/login/html
??????? CustomLog logs/login.log combined
??????? SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt??????
??????? SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
??????? SSLEngine on
??? </VirtualHost>

??? <Directory "/var/www/virtual/login/html">
??????? Require all granted
??? </Directory>
??? <VirtualHost *:80>
??????? ServerName login.westos.com
??????? RewriteEngine on
??????? RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
??? </VirtualHost>

?? 測試:
?? 不需要手動加??? login.westos.com

?? 注意:
?? ^(/.*)$?? ##客戶在瀏覽器地址欄中輸入的所有字符
?? https://? ##強制客戶加密訪問
?? %{HTTP_HOST}?? ##客戶請求主機
?? $1???????????? ##表示 ^(/.*)$ 的值
?? [redirect=301] ##臨時重寫? 302永久轉換
      

?

7.squid(FQ)

?? 在沒有權限查看某網站,另一個主機可以訪問的時候,可以在可以訪問的主機上裝squid,然后開啟服務,開通端口,在訪問不了的主機上,輸入可查看主機的ip和端口,就可以查看某網站
??
?? yum install squid -y
?? systemctl start squid
?? vim /etc/squid/squid.conf
??? http_access allow all
??? http_port 3128
??? cache_dir ufs /var/spool/squid 100 16 256
      

?

?? 測試:
?? 在真機上,preferences -> Advanced -> network -> setting -> Manual proxy configuration -> 172.25.254.110 3128
      

?

8.輔助squid

?? yum install squid -y
?? systemctl start squid
?? vim /etc/squid/squid.conf
??? http_access allow all
??? http_port 80 vhost vport
??? cache_peer 172.25.254.110 parent 80 0 proxy-only round-robin originserver name=web1? weight=3
??? cache_peer 172.25.254.111 parent 80 0 proxy-only round-robin originserver name=web2
??? cache_peer_domain web1 web2 www.westos.com

??? cache_dir ufs /var/spool/squid 100 16 256

?

? ??

?

轉載于:https://www.cnblogs.com/wf-aiyouwei/p/9482900.html

總結

以上是生活随笔為你收集整理的Linux从入门到精通——Apache的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。