Nginx编译安装

简介: nginx-1.12.1
+关注继续查看

1. 添加用户

useradd nginx
echo nginx:nginx|chpasswd

2.解压安装包

mkdir -p /home/nginx/soft
cd /home/nginx/soft
tar -xvf nginx-1.12.1.tar.gz
tar -xvf openssl-1.1.0h.tar.gz
tar -xvf pcre-8.42.tar.gz
tar -xvf zlib-1.2.11.tar.gz
tar -xvf v0.61.tar.gz
tar xf openssl-1.0.1t.tar.gz
tar xf openssl-1.0.1t.tar.gz 
tar xf perl-5.28.0.tar.gz 
tar xf v0.61.tar.gz 
tar xf pcre-8.39.tar.gz 
tar -xvf luajit2-2.1-20190912.tar.gz
tar -xvf ngx_devel_kit-0.3.1.tar.gz
tar -xvf lua-nginx-module-0.10.14.tar.gz
unzip nginx_upstream_check_module-master.zip
yum install -y gcc gcc-c++ 
chown -R nginx:nginx /home/nginx/soft/*
chmod -R 755 /home/nginx/soft/*

3.使用root用户安装lua模块

cd /home/nginx/soft/luajit2-2.1-20190912
make
make install

4.添加变量

[root@redis02 ~]# echo "/usr/local/lib" >>  /etc/ld.so.conf
[root@redis02 ~]# ldconfig
[root@redis02 ~]# vim /home/nginx/.bash_profile
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
[root@redis02 ~]# source /home/nginx/.bash_profile
[root@redis02 ~]# chown -R nginx:nginx /home/nginx/soft/

5.使用nginx用户安装其他模块

[root@redis02 ~]# su - nginx
cd /home/nginx/soft/pcre-8.42
  ./configure --prefix=/home/nginx/pcre-8.42
    make && make install
cd /home/nginx/soft/zlib-1.2.11
    ./configure --prefix=/home/nginx/zlib-1.2.11
  make && make install
cd /home/nginx/soft/openssl-1.1.0h
  ./config  --prefix=/home/nginx/openssl-1.1.0h
  make && make install
cd /home/nginx/soft/nginx-1.12.1
  ./configure --prefix=/home/nginx/nginx-1.12.1 \
  --with-http_stub_status_module \
  --with-http_ssl_module \
  --with-http_realip_module \
  --with-pcre=/home/nginx/soft/pcre-8.42 \
  --with-openssl=/home/nginx/soft/openssl-1.1.0h \
  --with-zlib=/home/nginx/soft/zlib-1.2.11 \
  --add-module=/home/nginx/soft/echo-nginx-module-0.61 \
  --add-module=/home/nginx/soft/ngx_devel_kit-0.3.1 
  --add-module=/home/nginx/soft/lua-nginx-module-0.10.14
  --add-module=/home/nginx/soft/nginx_upstream_check_module-master
  make -j2
  make install

5.报错解决

5.1 报错1

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

出现这个错误,是变量没有写进去,所以就添加下变量:

cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
echo “/usr/local/lib” >> /etc/ld.so.conf
ldconfig

然后就正常了。
可以去测试下:
修改nginx.conf配置文件
server加入:

location /hello {
default_type’text/plain’;
content_by_lua’ngx.say(“Hello Lua!”)’;
}

访问出现Hello Lua!提示就完全没问题了。
普通用户在restart和reload nginx时,会报错:

5.2 报错2

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/nginx/conf/nginx.conf:2

原因是:默认情况下Linux的 1024 以下端口是只有root用户才有权限占用

方法一

所有用户都可以运行(因为是755权限,文件所有者:root,组所有者:root)

chown root.root nginx
chmod 755 nginx
chmod u+s nginx

方法二

仅 root 用户和 wyq 用户可以运行(因为是750权限,文件所有者:root,组所有者:www)
chown root.www nginx
chmod 750 nginx
chmod u+s nginx

方法三

在sbin目录下使用管理员权限启动
sudo ./nginx

方法四

如果端口是大于1024的话,就注释掉 nginx.conf 中的 user root;
[root@redis02 ~]# cat /home/nginx/nginx-1.12.2/conf/nginx.conf

#user  root;
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       8888;
        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;
        }
    location /AssetWeb {
        proxy_pass $scheme://172.16.131.31:7100$request_uri;
    }

       location /ucenter {
            proxy_pass $scheme://172.16.131.31:8081$request_uri;
    }
    location /batch-xc {
        proxy_pass $scheme://172.16.131.31:8000$request_uri;
    }
        location /batch-guar {
         proxy_pass $scheme://172.16.131.133:8000$request_uri;
    }
        location /sms-web {
                proxy_ignore_client_abort on;
                proxy_pass $scheme://172.16.131.31:8000$request_uri;
        }
    #proxy_pass $scheme://172.16.131.49:8002$request_uri;
    #   }

        # 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;
    #    }
    #}
}
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
5天前
|
Ubuntu 应用服务中间件 nginx
百度搜索:蓝易云【Ubuntu 18.04系统编译安装Nginx 1.22教程。】
现在,您已经成功地在Ubuntu 18.04上编译和安装了Nginx 1.22。您可以通过在浏览器中访问服务器的IP地址来验证Nginx是否正常运行。请确保在实际操作中根据您的需求进行适当的配置和调整。请注意,通过编译安装方式安装的Nginx不会自动更新,您需要手动更新版本或进行维护。
27 1
|
13天前
|
应用服务中间件 nginx
百度搜索:蓝易云【Debian11系统编译安装Nginx教程。】
以上是在Debian 11系统上编译安装Nginx的基本步骤。请根据实际情况进行相应的调整和配置。
19 2
|
14天前
|
应用服务中间件 Linux 网络安全
百度搜索:蓝易云【Cnetos7编译安装Nginx教程。】
现在,您已经成功在CentOS 7上通过编译安装了Nginx。请注意,以上步骤提供了基本的指导,实际操作可能会有所差异。如有需要,您可以参考Nginx官方文档或社区资源获取更详细的信息和帮助。
32 0
|
2月前
|
应用服务中间件 Linux nginx
Linux下Nginx编译安装后的开机自启动设置
Linux下Nginx编译安装后的开机自启动设置
109 0
|
3月前
|
应用服务中间件 Linux 调度
编译安装nginx,实现调度功能
编译安装nginx,实现调度功能
|
6月前
|
人工智能 负载均衡 应用服务中间件
建议收藏chatGPT说的编译安装nginx教程
写在前面 这个是当下最流行最时髦的AI神器chatGPT和我一起合作写的一篇通用技术文章,请读者笑纳! chatGPT说 咚咚咚,咚咚咚,嘿嘿;咚咚咚,咚咚咚,嘿嘿;AI等一会,我来发答案,看图!!! 命令演示 首先,从nginx官方网站(https://nginx.org/en/download.html)下载最新的nginx源码包。 这里我们选择Stable version下的1.22.1版本,先下载然后解压源码包,具体步骤如下: wget https://nginx.org/download/nginx-1.22.1.tar.gz tar -zxvf nginx-1.22.1.ta
185 0
|
6月前
|
应用服务中间件 Linux nginx
Linux系统之Nginx的编译安装
Linux系统之Nginx的编译安装
219 2
Linux系统之Nginx的编译安装
|
10月前
编译安装Nginx时报错:没有那个文件或目录
编译安装Nginx时报错:没有那个文件或目录
147 0
编译安装Nginx时报错:没有那个文件或目录
|
10月前
|
应用服务中间件 Linux 网络安全
Linux下Nginx编译安装过程详解
Linux下Nginx编译安装过程详解
127 0
Linux下Nginx编译安装过程详解
|
应用服务中间件 Linux nginx
Linux环境编译安装Nginx
Linux环境编译安装Nginx
114 0
相关产品
云迁移中心
推荐文章
更多