nginx定义(来自百度百科):Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。
一、环境安装
1.1、gcc环境安装
-++
- 官方下载的nginx是源码,源码编译依赖 gcc 环境,如果没有 gcc 环境,需要安装 gcc:
1.2、pcre库安装
yum install -y pcre pcre-devel
- Perl 库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库。
1.3、zlib安装
yum install -y zlib zlib-devel
- nginx 使用 zlib 对 http 包的内容进行 gzip,所以需要在 linux 上安装 zlib 库,将文件进行解压
1.4、openssl安装
yum install -y openssl openssl-devel
- OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
- nginx 不仅支持 http 协议,还支持 https(即在 ssl 协议上传输 http),所以需要在 linux 安装 openssl 库。
1.5、nginx下载
wget http://nginx.org/download/nginx-1.13.4.tar.gz
二、nginx安装:
2.1、解压安装包
[root@bogon usr]
[root@bogon usr]
bin games lib libexec nginx-1.13.4 sbin src
etc include lib64 local nginx-1.13.4.tar.gz share tmp
2.2、进入nginx文件夹
[root@bogon usr]
[root@bogon nginx-1.13.4]
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
./configure --prefix=/usr/local/nginx
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
2.4、编译:
[root@bogon nginx-1.13.4]
编译成功后:
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/usr/nginx-1.13.4”
2.5、安装软件:
[root@bogon nginx-1.13.4]
安装成功:
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: 离开目录“/usr/nginx-1.13.4”
三、nginx启动
3.1、进入启动目录
[root@bogon nginx]
[root@bogon sbin]
nginx
3.2、检查nginx配置文件是否异常
[root@bogon sbin]
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.3、启动nginx:
[root@bogon sbin]
[root@bogon sbin]
3.4、停止nginx:
[root@bogon sbin]
[root@bogon sbin]
3.5、重新加载nginx配置文件并启动:
- 在使用nginx时会对配置文件进行修改,使用此命令重启比较方便
[root@bogon sbin]
[root@bogon sbin]
四、测试搭建是否成功
4.1、ip查看
[root@bogon sbin]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.58.163 netmask 255.255.255.0 broadcast 192.168.58.255
inet6 fe80::78b1:fa5a:1b0d:e135 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:d0:a7:16 txqueuelen 1000 (Ethernet)
RX packets 8726 bytes 1171186 (1.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7978 bytes 3215197 (3.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 579 bytes 661146 (645.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 579 bytes 661146 (645.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:6f:f1:fa txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- 说明:192.168.58.163为当前虚拟机ip
4.2、本机访问:192.168.58.163
- 如果出现欢迎界面则搭建成功
- 如果失败则需要查看当前的防火墙端口是否开放,如果端口问题移步博客:03 linux 防火墙配置