yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel
mkdir -p /home/dm/tools
1 wget http://nginx.org/download/nginx-1.8.1.tar.gz 2 ls -l 3 tar xf nginx-1.8.1.tar.gz 4 cd nginx-1.8.1/
建立www用户html
useradd www -s /sbin/nologin -M
1 ./configure --user=www --group=www --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module 2 make && make install
安装时指定版本号路径是为了便于查看区分当前使用的nginx版本,也方便之后升级。nginx
当nginx软件升级编译成带新版本号的版本后,删除原来的软链接,再从新创建新的到/application/nginx/ 的软链接就好。c++
ln -s /application/nginx-1.8.1 /application/nginx
1 root@nginx nginx-1.8.1]# ll /application/|grep nginx 2 lrwxrwxrwx 1 root root 24 8月 19 19:06 nginx -> /application/nginx-1.8.1 3 drwxr-xr-x 11 root root 151 8月 19 19:06 nginx-1.8.1
4 [root@nginx nginx-1.8.1]# ls -l /application/nginx 5 lrwxrwxrwx 1 root root 24 8月 19 19:06 /application//nginx -> /application/nginx-1.8.1 6 [root@nginx nginx-1.8.1]#
1 检查配置文件语法: 2 /application/nginx/sbin/nginx -t 3 4 启动nginx: 5 /application/nginx/sbin/nginx
1 [root@nginx nginx-1.8.1]# lsof -i :80 2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME 3 nginx 3663 root 6u IPv4 23418 0t0 TCP *:http (LISTEN) 4 nginx 3665 www 6u IPv4 23418 0t0 TCP *:http (LISTEN) 5 6 [root@nginx nginx-1.8.1]# netstat -lnt|grep 80 7 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
centos6开启方法: /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/init.d/iptables save service iptables restart centos7开启方法: firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload
1 [root@nginx nginx-1.8.1]# curl -I 192.168.200.102 2 HTTP/1.1 200 OK 3 Server: nginx/1.8.1 4 Date: Sun, 19 Aug 2018 12:20:40 GMT 5 Content-Type: text/html 6 Content-Length: 612 7 Last-Modified: Sun, 19 Aug 2018 11:06:05 GMT 8 Connection: keep-alive 9 ETag: "5b794f1d-264" 10 Accept-Ranges: bytes
一、在编译安装nginx时,能够使用./configure --help 查看相关参数帮助,下面是编译时指定的参数及简单说明:centos
1 --prefix=PATH set installation prefix #设置安装路径 2 --user=USER set non-privileged user for #设置用户权限 3 --group=GROUP set non-privileged group for #进程用户组权限 4 --with-http_stub_status_module enable ngx_http_stub_status_module #激活状态信息 5 --with-http_ssl_module enable ngx_http_ssl_module #激活ssl功能
二、nginx启动命令说明:app
1 /application/nginx/sbin/nginx -h 2 3 -V 显示版本信息和配置选项并退出; 4 -t 检测nginx配置文件是否正确; 5 -s 后面能够跟stop, quit, reopen, reload,用来中止和重启nginx服务;