安装pcre库
pcre库是为了使Nginx支持具备URI重写gongne那个的rewrite模块,这个模块必备的
[root@tz ~]# yum install pcre pcre-devel -y
[root@tz ~]# rpm -qa pcre pcre-devel pcre-7.8-7.el6.x86_64 pcre-devel-7.8-7.el6.x86_64
编译安装Nginx
安装Nginx基础依赖包
使用HTTPS服务会用到此模块
[root@tz ~]# yum -y install openssl openssl-devel
编译安装Nginx
[root@tz ~]# mkdir -p /home/tools
[root@tz ~]# cd /home/tools
[root@tz tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
[root@tz tools]# ls
nginx-1.6.3.tar.gz
[root@tz tools]# tar xf nginx-1.6.3.tar.gz
[root@tz nginx-1.6.3]# cd nginx-1.6.3
[root@tz nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
[root@tz nginx-1.6.3]# make
[root@tz nginx-1.6.3]# make install
[root@tz nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx
检查
[root@tz nginx-1.6.3]# ll /application|grep nginx lrwxrwxrwx. 1 root root 25 4月 22 11:41 nginx -> /application/nginx-1.6.3/ drwxr-xr-x. 6 root root 4096 4月 22 11:41 nginx-1.6.3 [root@tz nginx-1.6.3]# ll /application/nginx lrwxrwxrwx. 1 root root 25 4月 22 11:41 /application/nginx -> /application/nginx-1.6.3/
启动前检查配置
[root@tz nginx-1.6.3]# /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
启动
[root@tz nginx-1.6.3]# /application/nginx/sbin/nginx
查看Nginx服务对应端口是否开启
[root@tz nginx-1.6.3]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 40383 root 6u IPv4 197210 0t0 TCP *:http (LISTEN) nginx 40384 nginx 6u IPv4 197210 0t0 TCP *:http (LISTEN)
[root@tz nginx-1.6.3]# netstat -lnt|grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
[root@tz nginx-1.6.3]# ps -ef|grep nginx root 40383 1 0 11:45 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx nginx 40384 40383 0 11:45 ? 00:00:00 nginx: worker process root 45997 5066 0 11:53 pts/2 00:00:00 grep nginx
关闭iptables防火墙
[root@tz nginx-1.6.3]# iptables stop
使用浏览器访问
使用wget命令访问
[root@tz nginx-1.6.3]# wget 127.0.0.1
--2020-04-22 11:50:11-- http://127.0.0.1/
正在连接 127.0.0.1:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:612 [text/html]
正在保存至: “index.html”
100%[===================================================>] 612 --.-K/s in 0s
2020-04-22 11:50:11 (93.6 MB/s) - 已保存 “index.html” [612/612])
使用curl命令访问
[root@tz nginx-1.6.3]# curl 127.0.0.01 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> ...省略
查看Nginx编译时的参数
[root@tz nginx-1.6.3]# /application/nginx/sbin/nginx -V nginx version: nginx/1.6.3 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) TLS SNI support enabled configure arguments: --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
查看Web错误日志
[root@tz nginx-1.6.3]# cat /application/nginx/logs/error.log