关闭
首页>Linux>正文

Centos7.2 编译安装nginx

centos 2016-12-15 17:58:14
  • A+
  • 0
  • 3604
安装之前先把openssl升级到最新版,
升级方法请看这篇文章  centos升级openssl到1.0.2j

安装所需支持库
yum install gcc-c++ -y pcre pcre-devel zlib zlib-devel


创建组与启动用户
groupadd www
useradd -g www www -s /bin/false


下载并解压
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2


创建以下目录,可以自定义路径,军哥喜欢装在/server下挖鼻
mkdir -p /server/nginx/client_body_temp
mkdir /server/nginx/proxy_temp
mkdir /server/nginx/fastcgi_temp
mkdir /server/nginx/uwsgi_temp
mkdir /server/nginx/scgi_temp


由于升级了openssl到最新版,可能需要做一下设置,否则会出错
修改vi auto/lib/openssl/conf
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
修改为:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"


设定配置(注意,--with-openssl=/usr/local/openssl 这个为升级openssl时的路径)
./configure \
--prefix=/server/nginx \
--conf-path=/server/nginx/conf/nginx.conf \
--pid-path=/server/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/server/nginx/logs/error.log \
--http-log-path=/server/nginx/logs/access.log \
--with-openssl=/usr/local/openssl \
--with-http_gzip_static_module \
--with-http_ssl_module \
--http-client-body-temp-path=/server/nginx/client_body_temp \
--http-proxy-temp-path=/server/nginx/proxy_temp \
--http-fastcgi-temp-path=/server/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/server/nginx/uwsgi_temp \
--http-scgi-temp-path=/server/nginx/scgi_temp


编译并安装
make && make install


添加到系统服务启动
vim /lib/systemd/system/nginx.service


写入以下代码
[Unit]
Description=nginx.service
After=network.target

[Service]
Type=forking
ExecStart=/server/nginx/sbin/nginx
ExecReload=/server/nginx/sbin/nginx -s reload
ExecStop=/server/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target


给nginx.service754权限
chmod 754 /lib/systemd/system/nginx.service


设置开机启动
systemctl enable nginx.service 


启动nginx
/server/nginx/sbin/nginx


如果启动出现 nginx: [error] invalid PID number "" in "nginx.pid" 就执行下面再重启
/server/nginx/sbin/nginx -c /server/nginx/conf/nginx.conf


好了,大功告成,访问你的外网IP就能看到默认的页面了.

本文地址:https://www.awobaba.cn/view-15.html

版权声明:本文为原创文章,版权归 阿我巴巴 所有,欢迎分享本文,转载请保留出处!

分享

广告位

评论0 发表评论

还没有评论,赶快抢沙发吧!~
点击获取效验码

Copyright © 阿我巴巴 版权所有.

Process:0.00413s, Memory: 461.71K, Cache: redis. 渝ICP备16003772号

渝公网安备 50022802000338号

本站服务器由 腾讯云 提供