# 2. Nginx 安装
Linux:本文
Mac:brew install nginx
Windows:windows 下安装和配置 nginx (opens new window)
Docker:docker pull nginx
# 2.1 安装 openssl、zlib、gcc 依赖
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
# 2. 2 安装 pcre 依赖
下载 pcre 压缩文件
wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
解压
tar -zxvf pcre-8.37.tar.gz
进入 pcre 目录
cd pcre-8.37
编译
./configure
安装
make && make install
检查
pcre-config --version
# 2.3 安装 Nginx
我这个选的是 nginx-1.16.1
版本
下载 nginx 压缩文件
wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压
tar -zxvf nginx-1.16.1.tar.gz
进入 nginx 目录
cd nginx-1.16.1
编译
./configure
安装
make && make install
# 2.4 启动 Nginx
查看开放端口
firewall-cmd --list-all
输出:默认不开放端口
public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
设置开放端口
firewall-cmd --add-service=http --permanent firewall-cmd --add-port=80/tcp --permanent
重启防火墙
firewall-cmd --reload
再看开放端口
firewall-cmd --list-all
输出:已开放 80 端口
public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 80/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
进入
/usr/local/nginx/sbin
目录cd /usr/local/nginx/sbin
运行 nginx
./nginx
访问 nginx
curl 127.0.0.1
输出:
# curl 127.0.0.1 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>