实验环境:腾讯云Linux Centos7.2 X64、Nginx 1.12.2(安全组、防火墙请放行22,80端口)
安装目录:/usr/local/nginx/
源码下载目录:/root/
临时访问域名:nginx.mxsina.com
一、安装依赖及需要的软件
yum install gcc gcc- gcc+ pcre-devel openssl-devel wget -y
二、下载源码包
wget http://nginx.org/download/nginx-1.12.2.tar.gz
三、给nginx创建一个www用户及组不允许登录
groupadd www useradd -g www www -M -s /sbin/nologin
四、解压进入源码目录
tar -zxvf nginx-1.12.2.tar.gz cd nginx-1.12.2
五、预编译(此步骤有错误请勿继续,无错误请继续,如有错误请检查是否安装了依赖)
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-pcre --with-http_gzip_static_module
六、安装
make && make install
七、启动nginx,并且查看端口是否启动
cd /usr/local/nginx/sbin/ ./nginx netstat -ntlp
八、使用vim编辑器编写nginx启动脚本加入开机启动(vim的使用自行百科)
vim
/etc/init.d/nginxd
#!/bin/bash # # chkconfig: - 85 15 # description: Nginx is a World Wide Web server. # processname: nginx nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done" ;; stop) echo -n "Stopping Nginx" killall -9 nginx echo " done" ;; test) $nginx -t -c $conf ;; reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done" ;; restart) $0 stop $0 start ;; show) ps -aux|grep nginx ;; *) echo -n "Usage: $0 {start|restart|reload|stop|test|show}" ;; esac
八、加入系统开机启动,重启nginx
chmod 755 /etc/init.d/nginxd chkconfig nginxd on systemctl restart nginxd
九、浏览器访问域名或者你的IP即可
本文作者为SKY RING,转载请注明。