网上没有nginx1.9.5安装教程所以就做一个。现在nginx很火 来试下这个web服务器吧本文为nmfox.com原创转载请注明出处
先安装gcc 等
1 |
yum -y install gcc gcc-c++ wget |
.然后装一些库
1 |
yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel |
.进入默认的软件目录
1 |
cd /usr/local/src/ |
下载 nginx软件 nginx1.9.5软件包也是蛮小的下载不用很长时间
1 |
wget http://nginx.org/download/nginx-1.9.5.tar.gz |
然后解压文件.
1 |
tar zxvf nginx-1.9.5.tar.gz |
进入 nginx1.9.5的源码目录
1 |
cd nginx-1.9.5/ |
创建一个nginx目录用来存放运行的临时文件夹
1 |
mkdir -p /var/cache/nginx |
然后开始configure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nobody \ --group=nobody \ --with-pcre \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-mail \ --with-mail_ssl_module \ --with-file-aio \ --with-ipv6 \ --with-http_v2_module \ --with-threads \ --with-stream \ --with-stream_ssl_module |
接着make
1 |
make |
如果想看有没有报错也可以 echp $? 如果是0的话 就没有报错
然后make install
1 |
make install |
启动nginx
1 |
/usr/sbin/nginx |
用ps aux来查看nginx是否启动
1 |
ps aux|grep nginx |
发现已经启动。
那么我们加入到systemctl中先看下centos7中的systemctl是什么样的
systemctl is-enabled iptables.service
systemctl is-enabled servicename.service #查询服务是否开机启动(等同于chkconfig –list)
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl –failed #显示启动失败的服务
systemctl start nginx.service#启动服务(等同于service httpd start)
systemctl stop nginx.service#停止服务(等同于service httpd stop)
systemctl restart nginx.service#重启服务(等同于service httpd restart)
systemctl status nginx.service#查看服务是否运行(等同于service httpd status)
systemctl enable nginx.service#开机自启动服务(等同于chkconfig httpd on)
systemctl disable nginx.service#开机时禁用服务(等同于chkconfig httpd on)
—————————————————————————————————————
1 |
vim /usr/lib/systemd/system/nginx.service |
按i输入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[Unit] Description=nginx - high performance web server nmfox.com Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target |
编辑好后保存
然后开启开机启动
1 |
systemctl enable nginx.service |
当我们运行ecable后他会自动创建一个软连接ln -s ‘/usr/lib/systemd/system/nginx.service’ ‘/etc/systemd/system/multi-user.target.wants/nginx.service’
然后可以用这些命令关掉nginx
1 |
pkill -9 nginx |
后面可以用systemctl来操作nginx.service
1 |
systemctl start nginx.service |
如果要和php整合可以编辑/etc/nginx/nginx.conf
《linux-centos7中nginx1.9.5安装nginx1.9.5编译安装教程systemctl控制启动关闭》有2个想法