1. 程式人生 > >CentOS 7中Nginx1.9.5編譯安裝教程systemctl啟動

CentOS 7中Nginx1.9.5編譯安裝教程systemctl啟動

pat align temp prefix 軟件 復制代碼 all automake 軟件目錄

先安裝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

CentOS 7中Nginx1.9.5編譯安裝教程systemctl啟動