阿里云CentOS安装Nginx
最近在CentOS使用Nginx,记录一下这些步骤,以免每次用都去搜,也共享给大家参考。
安装配置Nginx
Nginx是一个高性能的HTTP和反向代理服务,许多的大型网站都会采用Nginx来进行HTTP服务器托管,当然我们这里也要采用Nginx,在安装Nginx之前,需要安装一些前置模块。
安装编译环境gcc g++: 进入到root目录: cd /root/
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装PCRE: PCRE功能是让nginx有rewrite功能,下载PCRE:
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压安装包:
tar zxvf pcre-8.35.tar.gz
进入安装包目录:cd pcre-8.35 编译:./configure 安装:make && make install
安装Nignx: 回到root目录: cd /root/
wget http://nginx.org/download/nginx-1.16.0.tar.gz
解压安装包:
tar zxvf nginx-1.16.0.tar.gz
注意,这里要选好当前解压地址,解压完成就是Nginx所在的目录,这里我们在root根目录下解压。 进入安装目录:
cd nginx-1.16.0
编译:./configure --with-http_ssl_module 安装:make && make install
默认情况下,nginx会安装到/usr/local/nginx
下面,你可以指定到安装到/root
目录下:
编译:./configure --prefix=/root/nginx --with-http_ssl_module 安装:make && make install
启动和停止Nginx
进入Nginx安装目录:
cd root/nginx/sbin/
停止Nginx:./nginx -s stop
启动Nginx:./nginx
配置文件地址:
vi root/nginx/conf/nginx.conf
修改阿里云组策略
注意,在开启nginx的http和https服务后,需要在阿里云的云服务器实例安全组策略中添加80端口和443端口的开启。
找到实例中的安全组配置:

进入之后,点击添加安全组配置:

添加http的80端口:

添加https的443端口:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)