1. 程式人生 > >3、Apache Server安裝&配置

3、Apache Server安裝&配置

一、前言

  • 前置知識?

二、安裝

  • 1、 安裝
yum install httpd
  • 2、 設定為開機啟動&啟用
systemctl enable httpd && systemctl start httpd
  • 3、 防火牆埠開放
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
  • 4、訪問
http://ip
#/usr/share/httpd/noindex/index.html

三、Web應用/站點配置

  • 1、新建站點目錄&index頁面
#建立站點根目錄
mkdir /var/www/web

#進入站點根目錄並建立index.html
cd /var/www/web && vi index.html

#寫入hello並儲存即可,方便後續測試使用
  • 2、建立站點配置目錄
mkdir /etc/httpd/sites
  • 3、修改預設配置
vi /etc/httpd/conf/httpd.conf

#增加項:
IncludeOptional /etc/httpd/sites/*.conf
  • 4、新建站點配置
vi /etc/httpd/sites/default.conf

#配置內容
<VirtualHost *:80>
    ServerName hello.html.com
    ServerAlias html.com
    DocumentRoot /var/www/web/
    ErrorLog /var/www/web/error.log
    CustomLog /var/www/web/requests.log combined
</VirtualHost>
  • 5、訪問測試

本地修改hosts檔案,把hello.html.com指向該CentOS伺服器IP,然後通過該域名訪問即可。

http://hello.html.com

  • 6、埠使用注意事項

1、虛擬機器繫結的埠一定是Apache監聽的埠
2、建議Apache使用81埠把80埠讓給Nginx

四、備註

  • 相關閱讀