操作系统的源自带 nginx 和 apache httpd,但都不是最新版本。
先安装几个源:
IUS 第三方综合软件扩展,在 https://ius.io/GettingStarted/ 找到系统对应的地址
rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
Nginx官方源,在 http://nginx.org/en/linux_packages.html 按照说明手动编辑源repo文件,或者在 http://nginx.org/packages/centos/ 按照目录结构找到对应的地址
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装 Apache Httpd
yum install httpd24u
安装完成后,系统服务名为httpd
# 启动httpd
systemctl start httpd
# 随系统启动httpd
systemctl enable httpd
配置文件在 /etc/httpd 下面
其中 conf 目录下为主配置文件, conf.d 目录下为扩展配置文件。
conf/httpd.conf 里比较重要的配置参数:
# 默认监听端口
Listen 80
# 网站文件路径
DocumentRoot "/var/www/html"
其他网站和权限等属性设置 请另行了解 。
安装 Nginx
yum install nginx
安装完成后,系统服务名为nginx
# 启动nginx
systemctl start nginx
# 随系统启动nginx
systemctl enable nginx
配置文件在 /etc/nginx 下面
主配置文件为 nginx.conf ,扩展配置文件在 conf.d 目录下
可以配置多个 server,每个 server 单独监听一个端口,为了方便可以将 server 放在一个单独的配置文件里,配置文件以 .conf 作为扩展名,将被设置引用。
默认配置在 default.conf 里,这里单独新建一个网站的配置文件 site.conf
# 把旗下所有的域名都跳转到主域名上
server {
listen 2000;
server_name site1.com site2.com site2.net www.site2.com www.site2.net;
return 301 $scheme://www.site1.com$request_uri;
}
server {
listen 2000;
server_name www.site1.com;
location / {
root /home/site;
index index.html index.htm;
# 目录浏览功能
autoindex off;
# 目录浏览文件大小精确显示,关闭后大文件将显示KB MB GB等
autoindex_exact_size off;
# 目录浏览文件时间显示,打开显示本地时区时间,关闭显示GMT时间
autoindex_localtime on;
}
}
后面主要就使用nginx作为网站的WEB服务器了。