美文网首页
Nginx(OpenResty)安装配置详解

Nginx(OpenResty)安装配置详解

作者: 我是孟小鱼呀 | 来源:发表于2019-08-21 16:50 被阅读0次

安装配置
OpenResty(也称为 ngx_openresty)是一个全功能的 Web 应用服务器。它打包了标准的 Nginx 核心,很多的常用的第三方模块,以及它们的大多数依赖项,所以本文介绍OpenResty安装,同时也包括具体编译参数信息的介绍。
1、安装所需依赖包

yum install -y gcc gcc-c++ curl wget perl bzip2 pcre-devel openssl-devel zlib-devel

2、下载OpenResty源到目录/opt下(该目录可自己选择)

 wget https://live400-storage.oss-cn-hangzhou.aliyuncs.com/source/nginx/openresty-1.13.6.2.tar.gz

3、解压

cd /opt
tar -zxvf openresty-1.13.6.2.tar.gz

4、配置

./configure 
--prefix=/usr/local/openresty #安装路径
--with-stream  #配置stream模块
--with-threads 
--with-http_ssl_module 
--with-http_v2_module 
--with-http_realip_module 
--with-http_gzip_static_module 
--with-http_stub_status_module 
--user=www 
--group=www 
--build="LiveOps build at `date +%Y-%m-%d`" 
--with-ld-opt="-Ijemalloc"

5、编译安装

gmake && gmake install

6、完成之后/usr/local/openresty/nginx目录如下

image.png

7、参数配置

user  www;#openresty的运行用户,配置时添加的参数--user
worker_processes  auto;#启动进程,通常设置成和cpu的数量相等

pid  /data/logs/nginx/nginx.pid;#pid文件存放目录

events {
    worker_connections  1024;# #单个后台worker process进程的最大并发链接数  
}

http {
    include       mime.types; #设定mime类型,类型由mime.type文件定义
    default_type  application/octet-stream; 

 #设定日志格式
    log_format  main  '"$remote_addr" - "$remote_user" [$time_local] "$request" "$request_body" '
                      '"$status" "$body_bytes_sent" "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$upstream_addr" "$upstream_response_time" "$request_time"';

    sendfile    on;
    tcp_nopush  on;
    #连接超时时间
    keepalive_timeout  65;
    #开启gzip压缩
    gzip  on;

    server_tokens  off;

    client_max_body_size  10m;
    #设定虚拟主机配置
    server {
        #侦听80端口
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }
       #错误页面
        error_page  404              /404.html;
        error_page  500 502 503 504  /50x.html;

        location = /50x.html {
            root  html;
        }
        #nginx状态页
        location /nginx_status {
            stub_status  on;
            access_log   off;
            allow        127.0.0.1;
            deny         all;
        }
    }

    include /usr/local/openresty/nginx/conf/vhost/*.conf;
}

8、新建用户和组、新建日志存放目录

groupadd www
useradd -g www www -s /sbin/nologin
mkdir -p /data/logs/nginx
mkdir /usr/local/openresty/nginx/conf/vhost #反向代理配置文件目录

9、启动openresty

/usr/local/openresty/bin/openresty -t #检查
/usr/local/openresty/bin/openresty -s reload

/usr/local/openresty/nginx/sbin/nginx  -t
/usr/local/openresty/nginx/sbin/nginx  -s reload #如果单独启动nginx

10、访问http://ip

image.png

相关文章

网友评论

      本文标题:Nginx(OpenResty)安装配置详解

      本文链接:https://www.haomeiwen.com/subject/tmlesctx.html