linux上安裝apache以及httpd.conf基本配置

來源:互聯網
上載者:User

標籤:

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配置請參照下面

  • #vi /etc/httpd/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基本配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.