標籤:
1.yum安裝apache
#yum install httpd -y
2.隨系統自啟動
#chkconfig httpd on
3.開啟apache
#service httpd start
PS:在CentOS裡Apache的預設文件路徑的位置是在/var/www/html,設定檔的路徑是/etc/httpd/conf/httpd.conf。其他的配置儲存在/etc/httpd/conf.d/ 檔案夾裡。
建議刪除/etc/httpd/conf.d/下的welcome.conf檔案
刪除指令 #rm -rf *.* (注釋:*.*改成/etc/httpd/conf.d/welcome.conf)
---
httpd.conf配置請參照下面
以下展示的是學新公園對預設值的修改。
#禁止顯示apache版本號碼
ServerTokens ProductOnly
ServerSignature Off
#連接埠監聽,我們將*改成了我們的獨立ip
Listen *:80
#我們開啟了兩個模組,其他模組預設設定
mod_rewrite.so #開啟.htaccess需要
mod_vhost_alias.so #設定虛擬機器需要
#我們將ServerAdmin改成我們自己的郵箱。
ServerAdmin [email protected]
#我們將ServerName導向固定ip,即將*改成我們的ip
ServerName *:80
#我們修改了DocumentRoot目錄
DocumentRoot /***
#將Options屬性改成FollowSymLinks
Options FollowSymLinks
#將AllowOverride屬性改成ALL以支援.htaccess
AllowOverride ALL
#我們配置了虛擬機器,我們把*更改成我們的ip
NameVirtualHost *:80
#虛擬機器上拒絕了直接通過ip訪問我們的網站,我們把*更改成我們的ip
<VirtualHost *:80>
ServerName *
<Location />
Order deny,allow
Deny from all
</Location>
</VirtualHost>
#我們將網域名稱綁定到伺服器,並將不帶3www的網域名稱301重新導向到帶www網域名稱
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot 一個目錄
ServerName 1try10.com
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^1try10.com [NC]
RewriteRule ^/(.*)$ http://www.1try10.com/$1 [L,R=301]
</ifModule>
ErrorLog /var/log/1try10.com-error_log
CustomLog /var/log/1try10.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot 一個目錄
ServerName www.1try10.com
ErrorLog /var/log/1try10.com-error_log
CustomLog /var/log/1try10.com-access_log common
</VirtualHost>
#我們設定了gzip壓縮
#gzip
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
DeflateCompressionLevel 5
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
</IfModule>
#TRACE和TRACK是用來調試web伺服器串連的HTTP方式.支援該方式的伺服器存在跨站指令碼漏洞,所以我們關閉了它
TraceEnable off
linux上安裝apache以及httpd.conf基本配置