阿里云CentOS7.6.1810部署nginx

故事前线:
一哥们阿里云部署nginx失败,下午说还搞得pcre,我凑那是啥子鬼?
然后晚上那哥们把账号密码发我了,远程上去5分钟搞定,顺便一提,那哥们机子配置超级low (1核1G内存40G硬盘),还是我们的32核32G内存80G硬盘的 PCL 爽丫
搞定以后,寻思好久没更文了,今天那就发一哈,所以本文就诞生了
本故事纯属虚构,如有雷同纯属巧合。


既然是在阿里云上部署
首先申请阿里云主机CentOS7.6.1810,如何申请以及购买萌新请自行百度,老司机都懂;
博主是个穷逼,所以使用 PCL,博主爱鹏城实验室开发者云 PCL ,因为是公益的,免费
但是使用的不是x86_64架构,而是鲲鹏arm64架构的
在这里插入图片描述
在这里插入图片描述


好,书回正传,

开启安装 NGINX 模式

nginx官网: http://nginx.org/
nginx下载目录: http://nginx.org/download/

1、下载nginx源码包

wget http://nginx.org/download/nginx-1.12.2.tar.gz

注意:

  • 1、安装前要先安装依赖
    yum -y install pcre-devel openssl openssl-devel gcc gcc-c++

  • 2、阿里云控制台要安全组放行端口,入口出口(阿里云安全这一块做的到位)

  • 3、把nginx做成系统服务,方便维护

2、解压nginx源码包

tar -zxf nginx-1.12.2.tar.gz

3、源码编译

./configure --prefix=/opt/installed/ting/nginx

3.1、报错

突现报错,好事啊,终于晓得那哥们说的鬼了

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

3.2、解决报错

./configure --prefix=/opt/installed/ting/nginx --without-http_rewrite_module

4、安装

make
make install

5、编辑配置文件

vim /opt/installed/ting/nginx/conf/nginx.conf

根据需求写咯,可以参考本博主之前两篇文章哟

孔子曰:“温故而知新,可以为师矣”

之前写的文章不是白写的,也得经常温习。


6、把nginx写入到系统服务

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/opt/installed/ting/nginx/sbin/nginx
ExecReload=/opt/installed/ting/nginx/sbin/nginx -s reload
ExecStop=/opt/installed/ting/nginx/conf/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

7、写完后先重新加载一下系统服务

systemctl daemon-reload

8、然后重启nginx服务

systemctl restart nginx

9、设置nginx服务开机自启动

systemctl enable nginx

10、浏览器访问哈

在这里插入图片描述
这就成功了!


打完收工!

等一等,好像还有什么没说。。。

最后总结下:

  • nginx安装目录
/opt/installed/ting/nginx
  • nginx.conf配置文件目录
/opt/installed/ting/nginx/conf/nginx.conf
  • 启动服务
systemctl start nginx
  • 停止服务
systemctl stop nginx
  • 重启服务
systemctl restart nginx
  • 查看服务状态
systemctl status nginx
  • 查看进程状态
ps -ef|grep nginx

2021年第5篇原创,欢迎大家 一键三连 哈!
对啦,都看到最后啦,欢迎各位小伙伴们关注博主微信公众号哈!

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/frdevolcqzyxynjds/article/details/114339110