国产欧美日韩高清专区手机版_国产AⅤ精品一区二区三区久久_中国少妇内射XXXHD免费_在线观看视频久最新av_亚洲av免费在线观看_我把护士日出水了视频_精品国产凹凸成AV人网站_女人被老外躁得好爽免费视频_国产精品制服丝袜无码

15年
網(wǎng)站建設(shè)經(jīng)驗(yàn)
佳速互聯(lián)
佳速觀點(diǎn)

當(dāng)前位置:首頁(yè) >> 常見(jiàn)問(wèn)題 >> CentOS 7.2 配置Apache服務(wù)(httpd)--上篇

CentOS 7.2 配置Apache服務(wù)(httpd)--上篇

編輯:深圳網(wǎng)站建設(shè)   來(lái)源:佳速互聯(lián)   瀏覽量:正在讀取   時(shí)間:2016-11-01

一、Apache簡(jiǎn)介

  • Apache HTTP Server(簡(jiǎn)稱Apache)是Apache軟件基金會(huì)的一個(gè)開(kāi)放源代碼的網(wǎng)頁(yè)服務(wù)器軟件,可以在大多數(shù)電腦操作系統(tǒng)中運(yùn)行,由于其跨平臺(tái)和安全性(盡管不斷有新的漏洞被發(fā)現(xiàn),但由于其開(kāi)放源代碼的特點(diǎn),漏洞總能被很快修補(bǔ)。因此總合來(lái)說(shuō),其安全性還是相當(dāng)高的。)。被廣泛使用,是最流行的Web服務(wù)器軟件之一。它快速、可靠并且可通過(guò)簡(jiǎn)單的API擴(kuò)充,將Perl/Python等解釋器編譯到服務(wù)器中。
  • 軟件圖標(biāo) 
    這里寫(xiě)圖片描述

二、安裝Apache httpd

  • 安裝httpd以配置Web服務(wù)器, HTTP使用80 / TCP
[1] 安裝 httpd.
[root@linuxprobe ~]# yum -y install httpd
# 刪除默認(rèn)歡迎頁(yè)面
[root@linuxprobe ~]# rm -f /etc/httpd/conf.d/welcome.conf
[2] 配置httpd,將服務(wù)器名稱替換為您自己的環(huán)境
[root@linuxprobe ~]# vi /etc/httpd/conf/httpd.conf
# line 86: 改變管理員的郵箱地址
ServerAdmin [email protected]
# line 95: 改變域名信息
ServerName www.linuxprobe.org:80
# line 151: none變成All
AllowOverride All
# line 164: 添加只能使用目錄名稱訪問(wèn)的文件名
DirectoryIndex index.html index.cgi index.php
# add follows to the end
# server's response header(安全性)
ServerTokens Prod
# keepalive is ON
KeepAlive On
[root@linuxprobe ~]# systemctl start httpd
[root@linuxprobe ~]# systemctl enable httpd
[3] 如果Firewalld正在運(yùn)行,請(qǐng)?jiān)试SHTTP服務(wù)。,HTTP使用80 / TCP
[root@linuxprobe ~]# firewall-cmd --add-service=http --permanent
success
[root@linuxprobe ~]# firewall-cmd --reload
success
[4] 創(chuàng)建一個(gè)HTML測(cè)試頁(yè),并使用Web瀏覽器從客戶端PC訪問(wèn)它。如果顯示以下頁(yè)面,是正確的
[root@linuxprobe ~]# vi /var/www/html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Welcome access LinuxProbe.org,This is Test Page!
</div>
</body>
</html>

這里寫(xiě)圖片描述

三、支持Perl

  • 啟用CGI執(zhí)行并使用Perl腳本
[1] 安裝Perl.
[root@linuxprobe ~]# yum -y install perl perl-CGI
[2] 默認(rèn)情況下,在“/var/www/cgi-bin”目錄下允許CGI。  
可以使用Perl Scripts放在目錄下。然而,它下面的所有文件都被處理為CGI。
# 下面的設(shè)置是CGI的設(shè)置
[root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
[3] 如果你想允許在其他目錄中的CGI,配置如下。  
例如,在“/var/www/html/cgi-enabled”中允許。
[root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
# create new
# processes .cgi and .pl as CGI scripts
<Directory "/var/www/html/cgi-enabled">
    Options +ExecCGI
    AddHandler cgi-script .cgi .pl
</Directory>
[root@linuxprobe ~]# systemctl restart httpd
[4] 如果SELinux被啟用,并且允許CGI在不是像上面[3]的默認(rèn)目錄下,更改規(guī)則如下。
[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/linuxprobe/html/cgi-enabled
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[5] 創(chuàng)建一個(gè)CGI測(cè)試頁(yè)面,并使用Web瀏覽器從客戶端PC訪問(wèn)它。如果顯示以下頁(yè)面,說(shuō)明配置正確。
[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.cgi
#!/usr/bin/perl
print "Content-type: text/html

";
print "<html>
<body>
";
print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
";
print "CGI Test Page";
print "
</div>
";
print "</body>
</html>
";
[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.cgi 

這里寫(xiě)圖片描述

四、支持PHP

  • 配置httpd以使用PHP腳本
[1] 安裝PHP.
[root@linuxprobe ~]# yum -y install php php-mbstring php-pear
[root@linuxprobe ~]# vi /etc/php.ini
# line 878: 取消注釋,設(shè)置時(shí)區(qū)
date.timezone = "Asia/Shanghai"
[root@linuxprobe ~]# systemctl restart httpd

[2] 創(chuàng)建一個(gè)PHP測(cè)試頁(yè)面,并使用Web瀏覽器從客戶端PC訪問(wèn)它。如果顯示以下頁(yè)面,它是確定。
[root@linuxprobe ~]# vi /var/www/html/index.php
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
<?php
   print Date("Y/m/d");
?>
</div>
</body>
</html>

這里寫(xiě)圖片描述

[3] 創(chuàng)建phpinfo測(cè)試頁(yè),確認(rèn)是都開(kāi)啟php支持
[root@linuxprobe ~]# echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

這里寫(xiě)圖片描述

五、支持Ruby

  • 配置httpd以將Ruby腳本用作CGI
[1] 安裝Ruby.
[root@linuxprobe ~]# yum -y install ruby

[2] 默認(rèn)情況下,在“/var/www/cgi-bin”目錄下允許CGI。  
可以使用Perl Scripts放在目錄下。然而,它下面的所有文件都被處理為CGI。
# 下面的設(shè)置是CGI的設(shè)置
[root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

[3] 如果你想允許在其他目錄中的CGI,配置如下。  
例如,在“/var/www/html/cgi-enabled”中允許。
[root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
# create new
# processes .rb as CGI scripts
<Directory "/var/www/html/cgi-enabled">
    Options +ExecCGI
    AddHandler cgi-script .rb
</Directory>
[root@linuxprobe ~]# systemctl restart httpd

[4] 如果SELinux被啟用,并且允許CGI在不是像上面[3]的默認(rèn)目錄下,更改規(guī)則如下。
[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[5]     Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.rb

#!/usr/bin/ruby
print "Content-type: text/html

"
print "<html>
<body>
"
print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
"
print "Ruby Script Test Page"
print "
</div>
"
print "</body>
</html>
" 
[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.rb 

這里寫(xiě)圖片描述

六、支持Python

  • 啟用CGI執(zhí)行并使用Python腳本
[1] 安裝python.
[root@linuxprobe ~]# yum -y install python

[2] 默認(rèn)情況下,在“/var/www/cgi-bin”目錄下允許CGI。  
可以使用Perl Scripts放在目錄下。然而,它下面的所有文件都被處理為CGI。
# 下面的設(shè)置是CGI的設(shè)置
[root@linuxprobe ~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
247: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

[3] 如果你想允許在其他目錄中的CGI,配置如下。  
例如,在“/var/www/html/cgi-enabled”中允許。
[root@linuxprobe ~]# vi /etc/httpd/conf.d/cgi-enabled.conf
# create new
# processes .py as CGI scripts
<Directory "/var/www/html/cgi-enabled">
    Options +ExecCGI
    AddHandler cgi-script .py
</Directory>
[root@linuxprobe ~]# systemctl restart httpd

[4] 如果SELinux被啟用,并且允許CGI在不是像上面[3]的默認(rèn)目錄下,更改規(guī)則如下。
[root@linuxprobe ~]# chcon -R -t httpd_sys_script_exec_t /var/www/html/cgi-enabled
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[5]     Create a CGI test page and access to it from client PC with web browser. It's OK if following page is shown.
[root@linuxprobe ~]# vi /var/www/html/cgi-enabled/index.py

#!/usr/bin/env python

print "Content-type: text/html

"
print "<html>
<body>
"
print "<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
"
print "Python Script Test Page"
print "
</div>
"
print "</body>
</html>
" 

[root@linuxprobe ~]# chmod 705 /var/www/html/cgi-enabled/index.py

這里寫(xiě)圖片描述

7、支持Userdir

  • 啟用userdir,用戶可以使用此設(shè)置創(chuàng)建網(wǎng)站
[1] 配置 httpd.
[root@linuxprobe ~]# vi /etc/httpd/conf.d/userdir.conf
# line 17: comment out
#UserDir disabled
# line 24: uncomment
UserDir public_html
# line 31 - 35

<Directory "/home/*/public_html">
    AllowOverride All
# change

    Options None
# change

    Require method GET POST OPTIONS
</Directory>
[root@linuxprobe ~]# systemctl restart httpd

[2] 創(chuàng)建一個(gè)測(cè)試頁(yè),使用普通用戶通過(guò)客戶端PC與Web瀏覽器和訪問(wèn)它,如果顯示以下頁(yè)面,就是正確的
[cent@linuxprobe ~]$ mkdir public_html

[cent@linuxprobe ~]$ chmod 711 /home/cent

[cent@linuxprobe ~]$ chmod 755 /home/cent/public_html

[cent@linuxprobe ~]$ vi ./public_html/index.html

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
UserDir Test Page
</div>
</body>
</html>

瀏覽器訪問(wèn):http://linuxprobe.org/~wang/,出現(xiàn)如下界面 
這里寫(xiě)圖片描述

8、設(shè)置虛擬主機(jī)

  • 配置虛擬主機(jī)以使用多個(gè)域名。 
    以下示例在域名為[linuxprobe.org],虛擬域名為[virtual.host(根目錄[/home/wang/public_html]]的環(huán)境中設(shè)置。 
    必須為此示例設(shè)置Userdir的設(shè)置
[1] 配置虛擬主機(jī)
[root@linuxprobe ~]# vi /etc/httpd/conf.d/vhost.conf
# for original domain

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName www.linuxprobe.org
</VirtualHost>
# for virtual domain

<VirtualHost *:80>
   DocumentRoot /home/cent/public_html
   ServerName www.virtual.host
   ServerAdmin [email protected]
   ErrorLog logs/virtual.host-error_log
   CustomLog logs/virtual.host-access_log combined
</VirtualHost>
[root@linuxprobe ~]# systemctl restart httpd

[2]創(chuàng)建測(cè)試頁(yè)并使用Web瀏覽器從客戶端計(jì)算機(jī)訪問(wèn)它。如果顯示以下頁(yè)面,則是正確的:
[cent@linuxprobe ~]$ vi ~/public_html/virtual.php
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Virtual Host Test Page
</div>
</body>
</html>
[3]如果訪問(wèn)測(cè)試時(shí)看不到相應(yīng)頁(yè)面,可通過(guò)下面命令進(jìn)行測(cè)試:
[root@linuxprobe ~]# yum -y install elinks^C
[root@linuxprobe ~]# elinks http://www.virtual.host/virtual.php

9、創(chuàng)建SSL證書(shū)

  • 創(chuàng)建自己的SSL證書(shū)。但是,如果您使用您的服務(wù)器作為業(yè)務(wù),最好購(gòu)買(mǎi)和使用來(lái)自Verisigh的正式證書(shū)等。
[root@linuxprobe ~]# cd /etc/pki/tls/cert
cert.pem  certs/    
[root@linuxprobe ~]# cd /etc/pki/tls/certs/
[root@linuxprobe certs]# make server.key
umask 77 ; 
/usr/bin/openssl genrsa -aes128 2048 > server.key
Generating RSA private key, 2048 bit long modulus
...............................................................+++
....................................................................................................+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
[root@linuxprobe certs]# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key:
writing RSA key
[root@linuxprobe certs]# make server.csr
umask 77 ; 
/usr/bin/openssl req -utf8 -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN    #國(guó)家后綴
State or Province Name (full name) []:Shanghai  #省
Locality Name (eg, city) [Default City]:Shanghai  #市
Organization Name (eg, company) [Default Company Ltd]:LinuxProbe  #公司
Organizational Unit Name (eg, section) []:DevOps  #部門(mén)
Common Name (eg, your name or your server's hostname) []:linuxprobe.org  #主機(jī)名
Email Address []:[email protected]  #郵箱

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:    #默認(rèn)
An optional company name []:    #默認(rèn)
#
[root@linuxprobe certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=LinuxProbe/OU=DevOps/CN=linuxprobe.org/[email protected]
Getting Private key

10、配置SSL

[1] 配置SSL.
[root@linuxprobe ~]# yum -y install mod_ssl
[root@linuxprobe ~]# vi /etc/httpd/conf.d/ssl.conf
# line 59: 取消注釋
DocumentRoot "/var/www/html"
# line 60: 取消注釋,定義域名
ServerName linuxprobe.org:443
# line 75: 改變SSLProtocol
SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2

# line 100: 改成剛剛創(chuàng)建的server.crt
SSLCertificateFile /etc/pki/tls/certs/server.crt
# line 107: 改成剛剛創(chuàng)建的server.key
SSLCertificateKeyFile /etc/pki/tls/certs/server.key
[root@www ~]# systemctl restart httpd

[2] 如果Firewalld正在運(yùn)行,請(qǐng)?jiān)试SHTTPS服務(wù)。 HTTPS使用443 / TCP
[root@www ~]# firewall-cmd --add-service=https --permanent
success
[root@www ~]# firewall-cmd --reload
success
[3] 使用Web瀏覽器通過(guò)HTTPS從客戶端計(jì)算機(jī)訪問(wèn)測(cè)試頁(yè)。下面的示例是Fiorefix。顯示以下屏幕,因?yàn)樽C書(shū)是自己創(chuàng)建的,但它沒(méi)有ploblem,繼續(xù)下一步。

這里寫(xiě)圖片描述

11、啟用基本身份驗(yàn)證

  • 啟用基本身份驗(yàn)證以限制特定網(wǎng)頁(yè)的訪問(wèn)
[1]例如,在目錄[/var/www/html/auth-basic]下設(shè)置基本身份驗(yàn)證設(shè)置。
 [root@linuxprobe ~]# vi /etc/httpd/conf.d/auth_basic.conf
# 創(chuàng)建新配置文件
<Directory /var/www/html/auth-basic>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/httpd/conf/.htpasswd
    require valid-user
</Directory>
# 添加用戶:使用“-c”創(chuàng)建新文件(僅為初始注冊(cè)添加“-c”選項(xiàng))
[root@linuxprobe ~]# htpasswd -c /etc/httpd/conf/.htpasswd wang

New password: # set password

Re-type new password: # confirm

Adding password for user wang
[root@linuxprobe ~]# systemctl restart httpd
[root@linuxprobe ~]# mkdir /var/www/html/auth-basic

[root@linuxprobe ~]# vi /var/www/html/auth-basic/index.html
# create a test page

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: wanger;">
Test Page for Basic Auth
</div>
</body>
</html>

[2] 使用Web瀏覽器從客戶端計(jì)算機(jī)訪問(wèn)測(cè)試頁(yè)。然后需要認(rèn)證,如下所示作為設(shè)置,用在[1]中添加的用戶回答

這里寫(xiě)圖片描述
[3] 訪問(wèn)成功 
這里寫(xiě)圖片描述

12、基本Auth + PAM

  • 限制特定網(wǎng)頁(yè)上的訪問(wèn),并使用OS用戶通過(guò)SSL連接進(jìn)行身份驗(yàn)證
[1] 創(chuàng)建證書(shū),請(qǐng)參照上文所述。
[2] 例如,在[/var/www/html/auth-pam]目錄下設(shè)置Basic Auth。
# install from EPEL
[root@linuxprobe ~]# yum --enablerepo=epel -y install mod_authnz_external pwauth
[root@linuxprobe ~]# vi /etc/httpd/conf.d/authnz_external.conf
# add to the end

<Directory /var/www/html/auth-pam>
    SSLRequireSSL
    AuthType Basic
    AuthName "PAM Authentication"
    AuthBasicProvider external
    AuthExternal pwauth
    require valid-user
</Directory>

[root@linuxprobe ~]# mkdir /var/www/html/auth-pam

[root@linuxprobe ~]# vi /var/www/html/auth-pam/index.html
# create a test page

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for PAM Auth
</div>
</body>
</html>

[root@linuxprobe ~]# systemctl restart httpd
[3]  在客戶端上使用Web瀏覽器訪問(wèn)測(cè)試頁(yè)面https://linuxprobe.org/auth-pam/,并與操作系統(tǒng)上的用戶進(jìn)行身份驗(yàn)證。

這里寫(xiě)圖片描述
這里寫(xiě)圖片描述

13、使用WebDAV

  • 下面是使用SSL連接配置WebDAV設(shè)置的示例
[1] 創(chuàng)建證書(shū),請(qǐng)參照上文所述
[2] 例如,創(chuàng)建一個(gè)目錄[webdav],它使得可以僅通過(guò)SSL連接到WebDAV目錄。
[root@linuxprobe ~]# mkdir /home/webdav
[root@linuxprobe ~]# chown apache. /home/webdav
[root@linuxprobe ~]# chmod 770 /home/webdav
[root@linuxprobe ~]# vi /etc/httpd/conf.d/webdav.conf
# create new
DavLockDB "/tmp/DavLock"
Alias /webdav /home/webdav
<Location /webdav>
    DAV On
    SSLRequireSSL
    Options None
    AuthType Basic
    AuthName WebDAV
    AuthUserFile /etc/httpd/conf/.htpasswd
    <RequireAny>
        Require method GET POST OPTIONS
        Require valid-user
    </RequireAny>
</Location>

#  添加用戶:使用“-c”創(chuàng)建新文件(僅為初始注冊(cè)添加“-c”選項(xiàng))
[root@linuxprobe ~]# htpasswd -c /etc/httpd/conf/.htpasswd wang
New password:     # set password
Re-type new password:
Adding password for user wang
# **注意:用戶wang的htpasswd已經(jīng)創(chuàng)建過(guò),不需要重復(fù)創(chuàng)建**
[root@linuxprobe ~]# systemctl restart httpd

[3]  如果啟用了SELinux,請(qǐng)更改以下規(guī)則。  
[root@linuxprobe ~]# chcon -R -t httpd_sys_rw_content_t /home/webdav
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_rw_content_t /home/webdav

[4]  這是PC上的WebDAV客戶端的設(shè)置(Windows 10)。
下載“CarotDAV”,這是一個(gè)免費(fèi)的WebDAV客戶端,從以下網(wǎng)站⇒ http://www.rei.to/carotdav_en.html ,下載后,安裝并啟動(dòng)CarotDAV,然后顯示以下屏幕,單擊“文件”按鈕并選擇“WebDAV”。 

這里寫(xiě)圖片描述

[5]在“設(shè)置名稱”字段中輸入任何名稱,并在“URI”字段中輸入[服務(wù)器名稱/ webdav目錄](méi),并輸入用戶名和密碼

這里寫(xiě)圖片描述

[7]配置添加如下,點(diǎn)擊它連接到服務(wù)器。 

這里寫(xiě)圖片描述

[8] waring顯示如下,它的SSL證書(shū)沒(méi)有安裝在您的電腦上,它沒(méi)有ploblem,點(diǎn)擊“忽略”,然后去下一步。 

這里寫(xiě)圖片描述

[9] 到webdav目錄下創(chuàng)建測(cè)試目錄和文件
[root@linuxprobe tmp]# cd /home/webdav/
[root@linuxprobe webdav]# mkdir linuxprobe
[root@linuxprobe webdav]# mkdir linuxcool
[root@linuxprobe webdav]# touch vdevops.txt
[root@linuxprobe webdav]# touch linuxcool.txt

這里寫(xiě)圖片描述



友情鏈接: 阿里云小店 找商網(wǎng) 阿里云金牌合作伙伴 深圳阿里云服務(wù)器 長(zhǎng)沙網(wǎng)站建設(shè) 深圳百度愛(ài)采購(gòu)?fù)茝V 深圳萬(wàn)網(wǎng)空間 深圳做網(wǎng)站 響應(yīng)式網(wǎng)站建設(shè) 寶安做網(wǎng)站 深圳設(shè)計(jì)網(wǎng)站 阿里云ICP備案 寶安網(wǎng)站建設(shè) 南山網(wǎng)站建設(shè) 深圳營(yíng)銷(xiāo)型網(wǎng)站建設(shè) 深圳品牌網(wǎng)站建設(shè) 深圳微信網(wǎng)站建設(shè) 西鄉(xiāng)網(wǎng)站建設(shè) 外貿(mào)網(wǎng)站建設(shè)
深圳網(wǎng)站建設(shè)
13723486509