Linux 下安装 Nginx 详细教程
# Nginx简介
Nginx是一款轻量级Web服务器,也是一款反向代理服务器。
- 可直接支持Rails和PHP的程序
- 可作为HTTP反向代理服务器
- 作为负载均衡服务器
- 作为邮件代理服务器
- 帮助实现前端动静分离
# Nginx相关资料
# Nginx下载安装
官网下载:http://nginx.org/en/download.html (opens new window),或者直接在linux执行命令:
wget http://nginx.org/download/nginx-1.12.2.tar.gz
1
安装Nginx
# 安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 解压缩
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2/
# 执行配置
./configure
# 编译安装(默认安装在/usr/local/nginx)
make
make install
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
修改配置文件
cd /usr/local/nginx/conf
vim nginx.conf
1
2
2
# Nginx相关命令
# 启动nginx
进入 /usr/local/nginx/sbin
目录,输入 ./nginx
即可启动 nginx
cd /usr/local/nginx/sbin
./nginx
1
2
2
# 关闭nginx
cd /usr/local/nginx/sbin
./nginx -s quit
# 或者
./nginx -s stop
1
2
3
4
2
3
4
# 重启nginx
cd /usr/local/nginx/sbin
./nginx -s reload
1
2
2
# 查看nginx进程
ps aux|grep nginx
# 或者
ps -ef|grep nginx
1
2
3
2
3
# 设置nginx开机启动
只需在rc.local
增加启动代码即可
vim /etc/rc.local
1
配置内容如下:
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
# 添加如下内容
/usr/local/nginx/sbin/nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
上次更新: 2024/01/30, 00:35:17
- 01
- Node与GLIBC_2.27不兼容解决方案08-19
- 02
- Git清空本地文件跟踪缓存08-13