阿里云centos7安装nginx
2021-08-27 本文已影响0人
JuliusL
【注】:本笔记参考:https://blog.csdn.net/weixin_42014622/article/details/102560705
目录
1,安装前的准备工作
2,安装nginx
3,nginx的启动和关闭
4,浏览器访问:http://阿里云公网ip地址:80
5,配置nginx
1,安装前的准备工作
# yum install gcc-c++
# yum install pcre pcre-devel
# yum install zlib zlib-devel
# yum install openssl openssl-devel
2,安装nginx
2.1,从官网下载稳定版nginx
官网地址:http://nginx.org/en/download.html
2.2,输入:wget http://nginx.org/download/nginx-1.20.1.tar.gz
wget http://nginx.org/download/nginx-1.20.1.tar.gz
2.3 解压:tar -zxvf nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
2.4 使用默认配置:./configure
image.png2.5 编译安装:make && make install
make && make install
2.5 查看nginx的位置:whereis nginx
[root@izo4t6je6mwbb8z nginx-1.20.1]# whereis nginx
nginx: /usr/lib64/nginx /etc/nginx /usr/local/nginx /usr/share/nginx
3,Nginx的启动和关闭
3.1,输入:/usr/local/nginx/sbin/nginx -t
[root@izo4t6je6mwbb8z nginx-1.20.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
3.2,进入nginx目录,看其版本
cd /usr/local/nginx
./sbin/nginx -V
3.3,启动nginx(默认配置文件)
[root@izo4t6je6mwbb8z nginx-1.20.1]# cd /usr/local/nginx
[root@izo4t6je6mwbb8z nginx]# ./sbin/nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments:
[root@izo4t6je6mwbb8z nginx]# ./sbin/nginx
[root@izo4t6je6mwbb8z nginx]# ps aux|grep nginx
root 24515 0.0 0.0 20512 620 ? Ss 05:41 0:00 nginx: master process ./sbin/nginx
nobody 24516 0.0 0.0 20956 1336 ? S 05:41 0:00 nginx: worker process
root 24519 0.0 0.0 112648 964 pts/0 R+ 05:41 0:00 grep --color=auto nginx
4,浏览器访问:http://阿里云公网ip地址:80
image.png5,配置nginx
5.1,打开nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80; # nginx所监听的ip与端口号
server_name localhost; # 服务名
#charset koi8-r; # 编码格式
#access_log logs/host.access.log main;
location / {
root html; # 根目录
index index.html index.htm; # 默认页
}
5.2 修改完配置文件后直接访问公网ip+配置的端口号就可以看到配置页的默认页了!
./sbin/nginx -t # 检测配置文件
./sbin/nginx # 启动nginx
6,配置uwsgi
serveice restart nginx
或者
# 查看nginx运行的进程号
netstat -tunlp | grep 8080
# 杀死nginx进程
kil -9 PID
# 启动
./nginx