linux上安装OpenResty(Nginx)

1. 安装依赖

yum install pcre-devel openssl-devel gcc curl postgresql-devel

2. 下载解压

#下载
wget -c https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz
#解压
tar -zxvf openresty-1.15.8.1rc2.tar.gz

3. 源码编译

//切换目录 
cd openresty-1.15.8.1rc2

//开始安装 ./configure #或者下面,后面是参数 不写默认就行
./configure 
--prefix=/usr/local/openresty/ 
--with-http_stub_status_module 
--with-luajit 
--without-http_redis2_module 
--with-http_iconv_module 
--with-http_postgres_module 
--with-stream gmake && gmake install

4. 添加环境变量

#打开配置文件
vim /etc/profile
#编写配置变量 
PATH=/usr/local/openresty/nginx/sbin:$PATH 
export PATH 
#保存退出

#执行生效命令:
source /etc/profile

#查看是否生效:
echo $PATH

查看配置结果  

linux上安装OpenResty(Nginx)_第1张图片

5. 添加仓库执行命令 

#加载依赖
yum install yum-utils
#下载repo
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

6. 执行安装

#安装
yum install openresty
#安装成功后 会在默认的目录如下:
/usr/local/openresty

7. 配置nginx

#默认已经安装好了nginx,在目录:/usr/local/openresty/nginx下。
#修改/usr/local/openresty/nginx/conf/nginx.conf ,将配置文件使用的根设置为root,目的就是将来要使
#用lua脚本的时候 ,直接可以加载在root下的lua脚本。

#进入openresty 中nginx
cd  /usr/local/openresty/nginx


#启动nginx
sbin/nginx -c conf/nginx.conf

#重启 OpenResty
nginx -s reload 
 

 
#vue打包好放在  /usr/local/openresty/nginx/html目录下
cd /usr/local/openresty/nginx/html

8. nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
#根据自己的需要修改端口
        listen       8000;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

你可能感兴趣的:(linux上安装OpenResty(Nginx))