1. 程式人生 > >基於linux下的apache伺服器

基於linux下的apache伺服器

apache(Web伺服器):

Apache是世界使用排名第一的Web伺服器軟體。它可以執行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等直譯器編譯到伺服器中。同時Apache音譯為阿帕奇,是北美印第安人的一個部落,叫阿帕奇族,在美國的西南部。也是一個基金會的名稱、一種武裝直升機等等。

Apacheweb伺服器軟體擁有以下特性:

Apache Server配置介面 Apache Server配置介面
1.支援最新的HTTP/1.1通訊協議
2.擁有簡單而強有力的基於檔案的配置過程
3.
支援通用閘道器介面 4.支援基於IP和基於域名的虛擬主機 5.支援多種方式的HTTP認證 6.整合Perl處理模組 7.整合代理伺服器模組 8.支援實時監視伺服器狀態和定製伺服器日誌 9.支援伺服器端包含指令(SSI) 10.支援安全Socket層(SSL) 11.提供使用者會話過程的跟蹤 12.支援FastCGI 13.通過第三方模組可以支援JavaServlets

阿帕奇的常規配置:

[root@localhost mnt]# yum install httpd -y  安裝阿帕奇服務

這裡寫圖片描述

[root@localhost mnt]# systemctl start httpd  開啟阿帕奇服務
[root@localhost html]# systemctl stop firewalld 關閉防火牆 [root@localhost mnt]# netstat -antlupe | grep httpd 檢視埠 tcp6 0 0 :::80 :::* LISTEN 0 67447 4947/httpd [root@localhost mnt]# cd /var/www/html/

這裡寫圖片描述

[root@localhost html]# vim index.html   在瀏覽器輸入172.25.254.121檢視

這裡寫圖片描述
這裡寫圖片描述

[root@localhost html]# vim index.html

這裡寫圖片描述
這裡寫圖片描述

[root@localhost html]# vim test.html
[root@localhost html]# cat test.html   加入絕對路徑測試,輸入172.25.254.121/test.html檢視
test.age

這裡寫圖片描述
這裡寫圖片描述

1,修改預設埠:

[root@localhost html]# vim /etc/httpd/conf/httpd.conf 更改埠為8080
[root@localhost html]# systemctl restart httpd   重啟httpd服務
[root@localhost html]# netstat -antlupe  | grep httpd  檢視埠
tcp6       0      0 :::8080                 :::*                    LISTEN      0          70526      5159/httpd 

這裡寫圖片描述

[root@localhost html]# vim /etc/httpd/conf/httpd.conf  將埠改回來
[root@localhost html]# systemctl restart httpd    重啟服務
[root@localhost html]# netstat -antlupe  | grep httpd   檢視埠
tcp6       0      0 :::80                   :::*                    LISTEN      0          70936      5198/httpd          

這裡寫圖片描述
操作演示:
這裡寫圖片描述

2, 修改預設釋出目錄:

[root@localhost html]# mkdir /haha/html -p
[root@localhost html]# cd /haha/html/
[root@localhost html]# vim index.html編輯預設釋出檔案

這裡寫圖片描述

[root@localhost html]# vim /etc/httpd/conf/httpd.conf 

這裡寫圖片描述

[root@localhost html]# systemctl restart httpd

這裡寫圖片描述

在瀏覽器測試:

這裡寫圖片描述

3,修改預設釋出檔案:

[root@localhost html]# vim xfl.html

這裡寫圖片描述

[root@localhost html]# vim /etc/httpd/conf/httpd.conf

這裡寫圖片描述

[root@localhost html]# systemctl restart httpd

這裡寫圖片描述

在瀏覽器測試:

這裡寫圖片描述

4、添加發布目錄及檔案:

[root@localhost html]# mkdir linux/
[root@localhost html]# ls
index.html  linux  xfl.html
[root@localhost html]# cd linux/
[root@localhost linux]# ls
[root@localhost linux]# vim index.html

這裡寫圖片描述

[root@localhost linux]# vim /etc/httpd/conf/httpd.conf
#將/haha/html下的目錄/linux也設定為可訪問的目錄以及裡面的檔案

這裡寫圖片描述

[root@localhost linux]# systemctl restart httpd

這裡寫圖片描述

在瀏覽器測試:

這裡寫圖片描述

基於IP的使用者認證:

[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  建立使用者
New password: 
Re-type new password: 
Adding password for user admin
[root@localhost httpd]# cat apacheuser 
admin:$apr1$/s.CSA09$.aDX.Tcgl8V7zKSDjjqqF0
[root@localhost httpd]# htpasswd -cm apacheuser tom    再次加入引數c會覆蓋原來的
New password: 
Re-type new password: 
Adding password for user tom
[root@localhost httpd]# cat apacheuser 
tom:$apr1$i4qTag3h$N6tq1/im23Go00jq/.jpS1
[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$i4qTag3h$N6tq1/im23Go00jq/.jpS1
admin:$apr1$tN60p7ht$H7iL10QCHKCL.QAfrsiIf.

這裡寫圖片描述

將之前註釋掉的預設目錄開啟,建立westos:

[root@testdb httpd]# cd /var/www/html/
[root@testdb html]# ls
index.html  ks.cfg  test.html
[root@testdb html]# mkdir westos   建立westos目錄
[root@testdb html]# cd westos/
[root@testdb westos]# vim index.html   寫入訪問時看到的檔案

這裡寫圖片描述

[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf   設定admin使用者

這裡寫圖片描述

[root@localhost httpd]# systemctl restart httpd  用瀏覽器檢視時需要登陸

這裡寫圖片描述
登陸admin使用者:
這裡寫圖片描述
可以檢視:
這裡寫圖片描述

[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf   設定建立的所有使用者

這裡寫圖片描述

[root@localhost httpd]# systemctl restart httpd 用瀏覽器檢視進行測試之前建立的tom使用者

這裡寫圖片描述
可以檢視:
這裡寫圖片描述

基於使用者的訪問認證:

[root@localhost ~]# cd /var/www/html
[root@localhost html]# ls
index.html  test.html
[root@localhost html]# mkdir westos  建立目錄
[root@localhost html]# ls
index.html  test.html  westos
[root@localhost html]# cd westos/
[root@localhost westos]# ls
[root@localhost westos]# vim index.html  建立檔案進行測試
[root@localhost westos]# cat index.html
<h1>westos's page </h1>

這裡寫圖片描述

[[email protected] westos]# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">
122         Order Allow,Deny   Allow在前先讀取Allow
123         Allow from All
124         Deny from 172.25.254.84  Deny會覆蓋Allow,意味著僅僅172.25.254.84的主機不可以檢視,也就是我的真機IP進行測試
125 </Directory>

首先將原來寫入的檔案註釋掉:
這裡寫圖片描述
配置黑名單:
這裡寫圖片描述

[root@localhost westos]# systemctl restart httpd  在瀏覽器測試172.25.254.121/westos/

真機在黑名單裡面不允許檢視:
這裡寫圖片描述
虛擬機器不在黑名單可以檢視:
這裡寫圖片描述

[[email protected] westos]# vim /etc/httpd/conf/httpd.conf  配置白名單
<Directory "/var/www/html/westos">
        Order Deny,Allow  Deny在前先讀取Deny
        Allow from 172.25.254.84
        Deny from All   意味著僅僅172.25.254.84可以檢視檔案內容
</Directory>

這裡寫圖片描述

[root@localhost westos]# systemctl restart httpd
[root@localhost westos]# vim /etc/httpd/conf/httpd.conf  白名單在真機和虛擬機器瀏覽器進行效果檢視

真機在白名單可以檢視:
這裡寫圖片描述
虛擬機器不在白名單不可以檢視檔案內容:
這裡寫圖片描述
恢復實驗環境:
這裡寫圖片描述
操作演示:
這裡寫圖片描述

虛擬主機設定:

在真機新增解析,因為在真機測試,瀏覽器在那兒就在那兒寫解析:

[root@foundation21 ~]# vim /etc/hosts 編輯配置檔案

這裡寫圖片描述

[[email protected] ~]# cat /etc/hosts 新增解析
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.254.250 content.example.com
172.25.254.121 www.westos.com news.westos.com music.westos.com login.westos.com

這裡寫圖片描述
在虛擬機器配置檔案:

[[email protected] httpd]# cd /etc/httpd
[[email protected] httpd]# ls
apacheuser  conf  conf.d  conf.modules.d  logs  modules  run
[[email protected] httpd]# cd conf.d/
[[email protected] conf.d]# ls
autoindex.conf  README  userdir.conf  welcome.conf
[[email protected] conf.d]# vim default.conf 設定配置檔案

這裡寫圖片描述

[[email protected] conf.d]# mkdir /var/www/virtual/westos.com/news/ -p   建立兩個目錄
[[email protected] conf.d]# mkdir /var/www/virtual/westos.com/music/ -p
[[email protected] conf.d]# vim /var/www/virtual/westos.com/news/index.html

這裡寫圖片描述

[[email protected] conf.d]# vim /var/www/virtual/westos.com/music/index.html

這裡寫圖片描述

[root@localhost conf.d]# vim news.conf 配置檔案

這裡寫圖片描述

[root@localhost conf.d]# cp news.conf music.conf  使用:%s/news/music/g替換檔案
[root@localhost conf.d]# vim music.conf 配置檔案

這裡寫圖片描述

[[email protected] conf.d]# systemctl restart httpd
[[email protected] conf.d]# ls
autoindex.conf  music.conf  README        welcome.conf
default.conf    news.conf   userdir.conf

這裡寫圖片描述

在瀏覽器分別測試會出現不同的效果:

1.www.westos.com

這裡寫圖片描述

2.news.wests.com

這裡寫圖片描述

3.music.westos.com

這裡寫圖片描述

簡述HTTPS和HTTP區別:

HTTPS是以安全為目標的HTTP通道,簡單講是HTTP的安全版。https協議需要到ca申請證書,一般免費證書很少,需要交費。而http是超文字傳輸協議,資訊是明文傳輸,https 則是具有安全性的ssl加密傳輸協議http和https使用的是完全不同的連線方式用的埠也不一樣,前者是80,後者是443。http的連線很簡單,是無狀態的。HTTPS協議是由SSL+HTTP協議構建的可進行加密傳輸、身份認證的網路協議 要比http協議安全。

安裝證書及其私鑰:

[root@localhost conf.d]# yum install mod_ssl.x86_64 -y 安裝服務

這裡寫圖片描述

[[email protected] conf.d]# ls /etc/httpd/conf.d/
autoindex.conf  music.conf  README    userdir.conf
default.conf    news.conf   ssl.conf  welcome.conf
[[email protected] conf.d]# systemctl restart httpd   重啟服務
[[email protected] conf.d]# yum install crypto-utils.x86_64 -y  安裝私鑰

這裡寫圖片描述

[root@localhost conf.d]# genkey www.westos.com 進入圖形化介面,第二次載入得敲擊鍵盤

這裡寫圖片描述


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    替換主配置檔案

這裡寫圖片描述
選取安裝金鑰大小:
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述
進入虛擬機器敲擊鍵盤,不然會一直卡著:
這裡寫圖片描述
詢問是否傳送一個證書請求到證書當局,點選NO
這裡寫圖片描述
這裡寫圖片描述
配置自己的證書:
這裡寫圖片描述

用另外一臺主機原因是方便替換配置檔案,其實都是連線的一個虛擬機器:

[[email protected] ~]# ssh [email protected]
[email protected]172.25.254.221's password: 
Last login: Sat May 26 21:32:23 2018
[[email protected] ~]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  music.conf  README    tmprequest    welcome.conf
default.conf    news.conf   ssl.conf  userdir.conf
[[email protected] conf.d]# vim ssl.conf 檢視主配置檔案進行替換

這裡寫圖片描述

[root@localhost conf.d]# systemctl restart httpd 重啟服務

這裡寫圖片描述

這裡寫圖片描述
這裡寫圖片描述
下載證書:
這裡寫圖片描述
展示證書:
這裡寫圖片描述

清楚網頁快取歷史的步驟,方便進行實驗演示:

這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述

網頁重寫:

在真機新增解析,加入login解析:

[root@foundation21 ~]# vim /etc/hosts  加入login解析

這裡寫圖片描述

在虛擬機器:

[[email protected] conf.d]# ls
autoindex.conf  music.conf  README    tmprequest    welcome.conf
default.conf    news.conf   ssl.conf  userdir.conf
[[email protected] conf.d]# cp news.conf login.conf
[[email protected] conf.d]# vim login.conf  編輯login配置檔案

這裡寫圖片描述

[root@localhost conf.d]# systemctl restart httpd
[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

這裡寫圖片描述

在瀏覽器測試是得點選下載證書就會出現自己所寫的內容:

這裡寫圖片描述
這裡寫圖片描述
當輸入login.westos.com會自動跳轉到https加密方式。
這裡寫圖片描述

簡述CGI和PHP語言:

CGI是通用閘道器協議,是開發動態網頁的一個標準,遵循這個標準就可以用BAT、CMD、sh、PERL、C、C++、PERL以及PHP等語言編寫程式處理網頁請求和返回資料到客戶端瀏覽器。CGI是協議和標準,是一種規範,不是語言。
PHP是一個動態網頁開發語言,主要用於處理瀏覽器提交的資料以及返回結果給瀏覽器。PHP可以以CGI方式工作,也可以以ISAPI、NSAPI等模組方式工作。

PHP語言支援:

一開始在瀏覽器輸入172.25.254.221查詢到Hello world
這裡寫圖片描述

[root@localhost conf.d]# cd /var/www/html/  
[root@localhost html]# ls
index.html  test.html  westos
[root@localhost html]# vim index.php

這裡寫圖片描述

[[email protected] html]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  login.conf  news.conf  ssl.conf    userdir.conf
default.conf    music.conf  README     tmprequest  welcome.conf
[[email protected] conf.d]# vim /etc/httpd/conf/httpd.conf 編輯改變預設訪問順序

這裡寫圖片描述

[root@localhost conf.d]# systemctl restart httpd   重啟服務進去瀏覽器檢視為空白

這裡寫圖片描述

[root@localhost conf.d]# yum install php -y  安裝PHP
[root@localhost conf.d]# systemctl restart httpd  重啟服務

這裡寫圖片描述
安裝之後在網頁測試就可以看到PHP介面:
這裡寫圖片描述

CGI語言支援:

[root@localhost conf.d]# cd /var/www/html/
[root@localhost html]# ls
index.html  index.php  test.html  westos
[root@localhost html]# mkdir cgi
[root@localhost html]# ls
cgi  index.html  index.php  test.html  westos
[root@localhost html]# vim cgi/index.cgi  編輯CGI配置檔案

這裡寫圖片描述

[root@localhost html]# chmod +x cgi/index.cgi   增加許可權
[root@localhost html]# systemctl restart httpd  重啟服務
[root@localhost html]# ./cgi/index.cgi  執行指令碼
Content-type: text/html

Tue May 29 23:02:38 EDT 2018
進入瀏覽器輸入172.25.254.121/cgi/index.cgi就會出現檔案內容而不執行

這裡寫圖片描述

[[email protected] html]# ls
cgi  index.html  index.php  test.html  westos
[[email protected] html]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  login.conf  news.conf  README    tmprequest    welcome.conf
default.conf    music.conf  php.conf   ssl.conf  userdir.conf
[[email protected] conf.d]# vim default.conf 編輯配置檔案

這裡寫圖片描述

[root@localhost conf.d]# systemctl restart httpd重啟服務
進去瀏覽器輸入172.25.254.121/cgi/index.cgi就會自動執行指令碼

這裡寫圖片描述

建立一個 Discuz論壇:

[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  test.html  westos
[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   test.html  utility
[root@localhost html]# chmod 777 /var/www/html/upload/ -R
[root@localhost html]# yum install php-mysql -y

這裡寫圖片描述

[root@localhost html]# systemctl restart httpd

這裡寫圖片描述
在瀏覽器輸入172.25.254.221/upload進去安裝。
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述
用之前建立的使用者認證進行登陸:
這裡寫圖片描述
這裡寫圖片描述

相關推薦

linuxApache伺服器配置虛擬域名

1. 修改httpd.conf 可以直接在Apache配置檔案的結尾新增如下程式碼,給Apache新增虛擬域名: NameVirtualHost *:80 <VirtualHost *:80> ServerName www.nine.com DocumentRoot

linuxapache伺服器的安裝、啟動、檢視

一、apache的安裝 1、下載原始碼 2、./configure --prefix=你自己想安裝的目錄 --enables-so 3、make  4、make install完成之後,會在你的安裝目錄中多出/bin  /htdoc /cgi-bin /conf 等資料夾,

基於linuxapache伺服器

apache(Web伺服器): Apache是世界使用排名第一的Web伺服器軟體。它可以執行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等直

Ubuntu Linuxapache基於域名的虛擬主機配置詳解

 Ubuntu Linux下apache基於域名的虛擬主機配置的詳細步驟:   最近在學習linux,今天在linux下配置了下虛擬主機,下面是步驟: 要配置的網站http://www.hx95.com 虛擬主機檔案 myweb 1、首先在 /etc/apache2/

linuxApache的安裝

linux Apache 安裝 Apache是一個基金會的名字,httpd才是我們需要安裝的軟件包apr和apr-util是一個通用的函數庫,它讓httpd可以不關聯底層操作系統平臺,可以很方便的移植,如果不安裝這兩個,httpd就無法工作。步驟1、下載httpd、apr和apr-utilwget

LinuxApache與tomcat的整合

一.jdk安裝 1.在www.sun.com中下載linu的jdk1.6,下載到/home/lijing/下 2.在當前目錄下,輸入sh jdk-6u2-linux-i586-rpm.bin   看到 安裝程式在詢問您是否尊守許可協議頁面 ,回車,空格都可以,看完協議. &

Linux代理伺服器配置

1.安裝squid [[email protected] ~]# yum install squid -y 安裝: squid.x86_64 7:3.5.20-12.el7.x86_64.rpm

LinuxLinux檢視伺服器配置的命令

目錄 一、伺服器型號 二、作業系統 三、CPU 四、記憶體 五、硬碟 六、其他 一、伺服器型號 dmidecode|grep "System Information" -A9|egrep "Manufacturer|Product" 二

linux伺服器上配置scrapy框架的python爬蟲,使用mysql資料庫儲存

最近在做把 爬蟲部署到伺服器上,爬下來的資料再存到資料庫裡。 因為伺服器是linux系統的,所以我們事先需要配置一些環境檔案以及依賴的庫 1、裝python 這一步沒啥好說的吧 2、裝pip,然後再用pip裝依賴的庫: pip install pymysql

對於Linux伺服器程式設計(2)

對於驚群問題,我們可以使用一個主執行緒來接受連線,並且把這個連線套接字傳遞到子程序裡面,讓子程序來處理這個連線。這種方法需要程序間通訊:通過Unix套接字來在程序之間傳遞套接字。【注意不能使用Unix套接字***直接***傳遞描述符到子程序,因為雖然父程序和子程序獲得的檔案描述符相同,但是子程序

對於Linux伺服器程式設計(1)

在Linux下面,對於海量連線並且每個連線在大部分時間裡面都是不活躍的情況下,我們使用Epoll來解決C10K[C10M]問題。 1.如何使用Epoll:man Epoll。即為三個系統呼叫。 2.在伺服器擁有多個CPU的情況下,我們需要多執行緒或者多程序來幫助我們提高程式的效能,所以就需要

LinuxApache安裝_學習記錄

Linux下Apache安裝_學習記錄 Centos 7 版本 一、Yum安裝Apache的實驗步驟: 1. Yum install httpd 2. 編輯/etc/httpd/conf/httpd.conf檔案,編輯內容如下: 刪除#ServerName

Linux Apache 的安裝與配置

1、安裝APR (Apache Portable Runtime) wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz tar -zxf apr-1.4.5.tar.gz cd apr-1.4.5 ./configure --pre

LinuxApache服務(wsgi)

wsgi WSGI是Web Server Gateway Interface的縮寫。以層的角度來看,WSGI所在層的位置低於CGI。但與CGI不同的是WSGI具有很強的伸縮性且能運行於多執行緒或多程序的環境下,這是因為WSGI只是一份標準並沒有定義如何去實現。實際上WSGI並非CGI,因

LinuxApache服務(CGI)

CGI (通用閘道器介面) CGI 是Web 伺服器執行時外部程式的規範,按CGI 編寫的程式可以擴充套件伺服器功能。CGI 應用程式能與瀏覽器進行互動,還可通過資料庫API 與資料庫伺服器等外部資料來源進行通訊,從資料庫伺服器中獲取資料。格式化為HTML文件後,傳送給瀏覽器,也可以將從

LinuxApache服務(php)

PHP (超文字前處理器) PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文字前處理器”)是一種通用開源指令碼語言。語法吸收了C語言、Java和Perl的特點,利於學習,使用廣泛,主要適用於Web開發領域。PHP 獨特的語法混合了C、Java、Per

LinuxApache服務的基本設定(企業級)

Apache Apache是世界使用排名第一的Web伺服器軟體。它可以執行在幾乎所有廣泛使用的計算機平臺上,由於其跨平臺和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等直譯器編譯到伺服器中。同時Apache音譯為阿帕

linuxApache預設安裝路徑

如果採用RPM包安裝,安裝路徑應在 /etc/httpd目錄下 apache配置檔案:/etc/httpd/conf/httpd.conf 可以修改相關的訪問路徑及配置 Apache模組路徑:/usr/sbin/apachectl 啟動模組 web目錄:/var/www/html 專案的儲存

Linux Apache storm 環境搭建

Linux 下Apache storm 環境搭建 寫在前面 Storm的搭建 zookeeper叢集的安裝 Storm的下載和安裝 寫在前面 網上有不少搭建storm環境的方法,我也是從這些方法開始學習stor

windowsapache伺服器無法正常啟動和訪問

配置apache伺服器之後啟動失敗 命令列通過 httpd.exe -k start測試,出現錯誤提示: “(OS 10048)通常每個套接字地址(協議/網路地址/埠)只允許使用一次。  : AH00072: make_sock: could not bind to add