CentOS 7中Nginx1.9.5编译安装教程systemctl启动

先安装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软件

  1. wget http://nginx.org/download/nginx-1.9.5.tar.gz
复制代码

如果这个下载太慢可以在这里下载http://nginx.org/download/nginx-1.9.5.tar.gz 下载完后yum -y intall lrzsz 装好上传工具
然后用rz上传到服务器 

然后解压文件.

  1. tar zxvf nginx-1.9.5.tar.gz
复制代码

进入 nginx1.9.5的源码  如果想改版本号 可以进入源码目录src/core/nginx.h更改

  1. cd nginx-1.9.5/
复制代码

创建一个nginx目录用来存放运行的临时文件夹

  1. mkdir -p /var/cache/nginx
复制代码

开始configure

  1. ./configure \
  2. --prefix=/usr/local/nginx \
  3. --sbin-path=/usr/sbin/nginx \
  4. --conf-path=/etc/nginx/nginx.conf \
  5. --error-log-path=/var/log/nginx/error.log \
  6. --http-log-path=/var/log/nginx/access.log \
  7. --pid-path=/var/run/nginx.pid \
  8. --lock-path=/var/run/nginx.lock \
  9. --http-client-body-temp-path=/var/cache/nginx/client_temp \
  10. --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  11. --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  12. --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  13. --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  14. --user=nobody \
  15. --group=nobody \
  16. --with-pcre \
  17. --with-http_v2_module \
  18. --with-http_ssl_module \
  19. --with-http_realip_module \
  20. --with-http_addition_module \
  21. --with-http_sub_module \
  22. --with-http_dav_module \
  23. --with-http_flv_module \
  24. --with-http_mp4_module \
  25. --with-http_gunzip_module \
  26. --with-http_gzip_static_module \
  27. --with-http_random_index_module \
  28. --with-http_secure_link_module \
  29. --with-http_stub_status_module \
  30. --with-http_auth_request_module \
  31. --with-mail \
  32. --with-mail_ssl_module \
  33. --with-file-aio \
  34. --with-ipv6 \
  35. --with-http_v2_module \
  36. --with-threads \
  37. --with-stream \
  38. --with-stream_ssl_module
复制代码

接着 编译

  1. make
复制代码

安装

  1. make install
复制代码

启动nginx

  1. /usr/sbin/nginx
复制代码

用ps aux来查看nginx是否启动

  1. ps aux|grep nginx
复制代码

然后配置服务

  1. vim /usr/lib/systemd/system/nginx.service
复制代码

按i输入以下内容

  1. [Unit]
  2. Description=nginx - high performance web server 
  3. Documentation=http://nginx.org/en/docs/
  4. After=network.target remote-fs.target nss-lookup.target
  5. [Service]
  6. Type=forking
  7. PIDFile=/var/run/nginx.pid
  8. ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
  9. ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
  10. ExecReload=/bin/kill -s HUP $MAINPID
  11. ExecStop=/bin/kill -s QUIT $MAINPID
  12. PrivateTmp=true
  13. [Install]
  14. WantedBy=multi-user.target
复制代码

编辑好后保存
然后开启开机启动

  1. systemctl enable nginx.service
复制代码

用命令关掉nginx

  1. pkill -9 nginx
复制代码

后面可以用systemctl来操作nginx.service

  1. systemctl start nginx.service
复制代码

然后php装好后更改配置 编辑/etc/nginx/nginx.conf

posted on 2017-08-21 22:21  zhangzongshan  阅读(188)  评论(0编辑  收藏  举报

导航