Centos7 安装 nginx 的详细过程,我会通过 “环境准备”、“安装步骤” 来告诉你如何操作~
1. 环境准备
- 阿里云ECS云服务器
- CentOS 7.5 64位
2. 安装步骤
- 安装
nginx
yum -y install nginx
- 启动
nginx
service nginx start
- 访问验证(nginx 默认端口 80,故直接访问服务器的ip地址即可,若出现 nginx 的页面,则说明安装成功)
3. 其他操作
1)配置 nginx
nginx 配置文件通常存放的路径为:/etc/nginx/conf.d/
,在该目录下新建配置文件即可,这里以 default.conf
为例,简单的配置内容如下:
server
{
listen 80; # 监听的端口 http是80,https是443
server_name www.xxx.com; # 你的域名
# 页面访问路径
location / {
root /xxx/xxx; # 指向index.html的目录(路径相对于根目录,即与root目录同级)
try_files $uri $uri/ /index.html; # 解决刷新报404的问题
index index.html index.htm; # 文件
}
}
2)重启 nginx
- 方法一:
service nginx restart
- 方法二:
nginx -s reload