天天看點

linux基礎&http與https不同點及相關實驗提升✍

HTTP:

linux基礎&http與https不同點及相關實驗提升✍

WWW:

linux基礎&http與https不同點及相關實驗提升✍

基本配置以及常用檔案目錄

httpd.conf檔案的格式

Web服務的基本配置

設定目錄權限

虛拟主機的配置

https的配置

先介紹下apache的常用目錄

1.1這個是apache的所有配置檔案存放的目錄

linux基礎&http與https不同點及相關實驗提升✍

1.2網頁預設放置的路徑

Cgi-bin 是一種特殊的目錄,在進行互動式的www通路(如填寫線上表格)時,需要對伺服器上有相應程式對通路這輸入的資訊進行處理,這寫程式就是就是cgi程式。而這些程式隻能放在cgi-bin這個目錄

linux基礎&http與https不同點及相關實驗提升✍

1.3Apache的主配置檔案

linux基礎&http與https不同點及相關實驗提升✍

httpd.conf配置檔案主要由3個部分組成

全局環境

主伺服器配置

虛拟主機

每部分都有相應的配置語句,該檔案所有配置語句的文法為“配置參數名稱 參數值”的形式。

httpd.conf的配置語句除了選項的參數值以外,所有選項指令均不區分大小寫,可以在每一行前用“#”号表示注釋。

全局配置的相關參數,全局的參數一般不用改動

配置路徑: /etc/httpd/*

主配置目錄: /etc/httpd/conf

子配置目錄: /etc/httpd/conf.d(apache是一個子產品化的一個配置服務,是以我們可以根據每個子產品進行一些配置,不僅對程式本身進行子產品化配置對配置檔案也進行了子產品化配置)

<>

</>

主配置檔案介紹:

ServerRoot “/etc/httpd” 服務配置檔案的根設定apache安裝的絕對路徑

Listen 80 監聽端口

Include conf.modules.d/.conf

User apache 程序屬主

Group apache

ServerAdmin [email protected] 服務管理者郵箱

ServerName 0.0.0.0:80 服務名

目錄标簽

AllowOverride none 可以覆寫前面的配置

Require all denied 禁止通路根

DocumentRoot “/var/www/html” 文檔根目錄

<Directory “/var/www”>

AllowOverride None

Require all granted

<Directory “/var/www/html”>

Options Indexes FollowSymLinks 選項索引跟蹤軟連接配接

AllowOverride None

Require all granted

設定文檔目錄通路權限

DirectoryIndex index.html 索引目錄為index.html

<Files ".ht"> 安全政策控制檔案都是以.ht開頭

Require all denied

ErrorLog “logs/error_log” 連結到日志的檔案

LogLevel warn

LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” combined

%h 用戶端IP

%l 使用identd時才會有資訊,一般情況下都是-

%u 遠端使用者(從驗證擷取到的)

%t 收到請求時的時間

%r 請求的首行

%s 伺服器端傳回的狀态碼

%b 除HTTP頭以外的傳回的位元組數

%{Referer}i 從那個頁面連結跳轉到的此頁面

%{User-agent}i 使用者的User-Agent

LogFormat “%h %l %u %t “%r” %>s %b” common

LogFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i” %I %O” combinedio

CustomLog “logs/access_log” combined

ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”

<Directory “/var/www/cgi-bin”>

AllowOverride None

Options None

Require all granted

TypesConfig /etc/mime.types

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

AddType text/html .shtml

AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8 字元集

MIMEMagicFile conf/magic

EnableSendfile on 支援發送檔案

IncludeOptional conf.d/*.conf 包括選項子配置檔案

/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf

MIME(Multipurpose Internet Mail Extensions)多用途網際網路郵件擴充類型。是設定某種擴充名的檔案用一種應用程式來打開的方式類型,當該擴充名檔案被通路的時候,浏覽器會自動使用指定應用程式來打開。多用于指定一些用戶端自定義的檔案名,以及一些媒體檔案打開方式。

它是一個網際網路标準,擴充了電子郵件标準,使其能夠支援:

Https

linux基礎&amp;http與https不同點及相關實驗提升✍
linux基礎&amp;http與https不同點及相關實驗提升✍

1.CA憑證

linux基礎&amp;http與https不同點及相關實驗提升✍

2.基于虛拟目錄和使用者控制的web網站

[[email protected] ~]# htpasswd -c /etc/httpd/mymima abc(-c表示建立)

輸入密碼

[[email protected] ~]# htpasswd /etc/httpd/mymima tom

輸入密碼

[[email protected] ~]# mkdir /usr/local/mysecret

[[email protected] ~]# echo this is my secret > /usr/local/mysecret/index.html

[[email protected] ~]# vim /etc/httpd/conf.d/vhosts.conf

linux基礎&amp;http與https不同點及相關實驗提升✍

AuthType Basic 基本認證類型(賬号)

AuthName “Please login:” 提示資訊,雙引号必須有,可以更換為其它提示資訊

AuthUserFile /etc/httpd/mymima 使用者認證檔案的使用者名和密碼指定的檔案所在位置

Require user xiaoming xiaohong 指定這兩個使用者可以通路該伺服器

[[email protected] ~]#systemctl restart httpd
在浏覽器中輸入:http://192.168.227.140/mimi
【登入成功後實際上通路的是/usr/local/mysecret/index.html的内容】
會彈出如下需要輸入使用者名和密碼的視窗:
           
linux基礎&amp;http與https不同點及相關實驗提升✍
如果顯示類似如下提示:
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
           

來自 http://192.168.227.140/mimi

将下圖中的“啟用彈出視窗阻止程式”的勾去掉

linux基礎&amp;http與https不同點及相關實驗提升✍
3.動态網站搭建
安裝包mod_wsgi      //web server Gateway Interface// alt 屬性是一個必需的屬性,它規定在圖像無法顯示時的替代文本
動态網頁:在伺服器端存儲的文檔非HTML格式,是由程式設計語言開發的腳本,腳本在接受用戶端的參數之後進行執行,執行後生成html格式的文檔,然後把生成的網頁發給用戶端。
           

Listen 8909

mkdir /var/www/alt

<Directory “/var/www/alt”>

AllowOverride None

# Allow open access:

Require all granted

<VirtualHost 192.168.0.129:8909>

WSGIScriptAlias / /var/www/alt/webinfo.wsgi

linux基礎&amp;http與https不同點及相關實驗提升✍

python腳本内容 vim /var/www/alt/webinfo.wsgi

def application(environ, start_response):

status = ‘200 OK’

output = ‘Hello World’

response_headers = [(‘Content-type’, ‘text/plain’),

(‘Content-Length’, str(len(output)))]

start_response(status, response_headers)

return [output]

application 是一個接受接受兩個參數environ, start_response的标準 wsgi app:

environ: 一個包含請求資訊及環境資訊的字典, server 端會詳細說明

start_response: 一個接受兩個參數

status, response_headers

的方法:

status: 傳回狀态碼,如 http 200 、 404 等

response_headers: 傳回資訊頭部清單

linux基礎&amp;http與https不同點及相關實驗提升✍

繼續閱讀