Nginx源码编译安装

Nginx安装

一键脚本

# 会把nginx安装到/home/app/nginx里
# 创建用户
adduser nginx
# 创建临时文件目录
mkdir -p /home/app/nginx/tmp
# 安装依赖的库
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel perl perl-devel perl-ExtUtils-Embed
# 下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar xzvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
# 配置nginx
./configure --prefix=/home/app/nginx \
--user=nginx \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_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_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--http-client-body-temp-path=/home/app/nginx/tmp/client_body_temp \
--http-proxy-temp-path=/home/app/nginx/tmp/proxy_temp \
--http-fastcgi-temp-path=/home/app/nginx/tmp/fastcgi_temp \
--http-uwsgi-temp-path=/home/app/nginx/tmp/uwsgi_temp \
--http-scgi-temp-path=/home/app/nginx/tmp/scgi_temp \
--with-mail \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module 
# 编译并安装
make && make install
# 启动nginx
/home/app/nginx/sbin/nginx

Linux下安装

  1. 安装依赖

    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
    
  2. 下载nginx

    wget http://nginx.org/download/nginx-1.14.0.tar.gz
    
  3. 安装nginx

    要先配置一下安装选项,选项很多,参考官方链接

    这里给一份自己使用的
    定义了把nginx安装到/home/app/nginx目录下,安装ssl模块

    cd nginx-1.14.0
    ./configure --prefix=/home/app/nginx --with-http_ssl_module
    make
    make install
    
  4. 配置nginx

    ./conf/nginx.conf是nginx的配置文件,官方介绍

  5. 启动nginx

    使用命令启动

    ./sbin/nginx
    

    如果在运行期间更改了配置文件,可以使用-s参数控制程序更新

    ./sbin/nginx -s relaod
    
  6. 测试成功

    访问localhost:80可以看到欢迎页,说明安装运行成功

    curl localhost
    

    不成功的话请检查防火墙

常见问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值