本文共 1882 字,大约阅读时间需要 6 分钟。
本次的实验环境如下表所示:
操作系统 | 服务器IP | hostname |
---|---|---|
CentOS7.6 | 192.168.1.41 | mufengrow41 |
操作系统版本:
[root@mufengrow ~]# cat /etc/redhat-releaseCentOS Linux release 7.6.1810 (Core)
服务器IP:
[root@mufengrow ~]# ip a
查看具体IP地址,可在结果中找到对应的eth0或eno1所示IP。
安装Yum源
首先确保系统上有最新的Yum仓库源可用:
yum clean allyum -y updateyum -y install centos-release
启用nginx模块
CentOS7默认没有安装Nginx模块,可以通过安装nginx
和相关模块:
yum -y install nginx
或者选择特定的模块安装:
yum -y install nginx mod_ssl mod_rewrite mod téléphone
安装Nginx
运行安装命令:
yum -y install nginx
完成后可以通过检查版本确认是否安装成功:
nginx -v
下载Nginx源码
Defineeer到Nginx的官方仓库下载最新版本主线版本:
wget http://nginx.org/downloads/nginx-1.17.0.tar.gz
编译与安装
解压源码文件:
tar -xzvf nginx-1.17.0.tar.gz
进入构建目录:
cd nginx-1.17.0
会"/usr/local/nginx",为找到的默认目录。或指定其他安装目录:
./configure --prefix=/usr/local/nginx --builddir=/usr/local/nginx/tmp
编译:
makemake install
检查安装是否成功:
ls /usr/local/nginx/
拉取Nginx镜像
docker pull nginx:latest
运行Nginx容器
docker run -d --name nginx-server -p 80:80 nginx:latest
访问服务
在浏览器访问你的服务器IP或者localhost
,如果映射到了80端口,可以访问http://IP:80
检查Nginx运行状态
查看日志:
tail -f /usr/local/nginx/logs/error.log
防火墙设置
如果使用防火墙,记得开放HTTP/HTTPS端口:
firewall-cmd --permanent --add-service=http --add-port=80firewall-cmd --permanent --add-service=https --add-port=443
服务启动后重启防火墙:
systemctl restart iptables
设置Cache
echo 'server { listen 80; server_name your_domain.com; location / { proxy_pass http://localhost:80; proxy_set_header Host "$host"; proxy_set_header X-Real-IP $remote_addr; } location /ीआई{ proxy_pass http://backend_domain:port; } location /čas { alias /usr/share/nginx/html; access_log off; }
}' > /etc/nginx/conf.d/default.conf
- 重新加载服务:```bashsystemctl restart nginx
安装完毕后,请根据需要对服务进行进一步优化,打开防火墙设置,设置Cache等功能,以确保服务器高效稳定运行。
如有疑问,请重新查看配置,查阅Nginx官方文档或论坛进行解答。
转载地址:http://ipeyk.baihongyu.com/