nginx 编译安装

1、nginx安装

1.1、下载包
wget    http://nginx.org/en/download.html
1.2、解压编译
cd nginx-1.19.9
#编译,
#--prefix 指定安装目录
# --pid-path 指定pid路径
# --error-log-path 指定错误日志路径
#  --with 安装必要的模块
./configure --prefix=/opt/nginx    --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module

#安装
make && make install

ln -s /app/nginx/sbin/nginx /usr/bin/nginx
1.3、启动
nginx 

2、已安装nginx编译添加模块

2.1、查看原有编译参数
nginx -V
#响应如下
configure arguments: --prefix=/opt/nginx --with-http_sub_module --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module --with-http_ssl_module
image.png
2.2、添加需要编译模块组装编译命令
cd nginx-1.19.9
./configure --prefix=/opt/nginx --with-http_sub_module --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module --with-http_ssl_module
2.3、重复以上步骤1.2,1.3操作

3、nginx代理tcp请求

3.1 检查nginx是否添加了stream模块
nginx -V
3.2、如果没有重复删除目录重新编译
./configure --prefix=/opt/nginx    --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module  --with-stream --with-http_ssl_module --with-http_sub_module
3.3、nginx.conf配置

Steam 模块配置与http模块同级,完整配置如下

    #user  nobody;
    worker_processes  1;

    events {
        worker_connections  1024;
    }

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

        sendfile        on;
        keepalive_timeout  65;

        server {
            listen       8081;
            server_name  bst-site.data.sf-express.com;
            #access_log  logs/host.access.log  main;
            location / {
                root /var/www/html/dist;
                index index.html;
            }

            location /portal/ {
                proxy_pass http://10.120.8.31:9092;
            }
        }

       
    }

    stream {
        upstream sftp{
            hash $remote_addr consistent;
            server 172.25.32.16:22;
        }
        
        server {
            listen 10022;
            proxy_connect_timeout 300s;
            proxy_timeout 300s;
            proxy_pass sftp;
       }
    }

感谢老哥https://blog.csdn.net/zhuimeng_by/article/details/107046290

常见问题

1、centos8安装报错

错误信息1:

Nginx安装时出现In function ‘ngx_murmur_hash2’等错误

    src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
    src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
             h ^= data[2] << 16;
             ~~^~~~~~~~~~~~~~~~
    src/core/ngx_murmurhash.c:38:5: note: here
         case 2:
         ^~~~
    src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
             h ^= data[1] << 8;
             ~~^~~~~~~~~~~~~~~
    src/core/ngx_murmurhash.c:40:5: note: here
         case 1:
         ^~~~
    cc1: all warnings being treated as errors
    make[1]: *** [objs/Makefile:432: objs/src/core/ngx_murmurhash.o] Error 1

原因:将警告信息当作错误信息进行了处理
解决方法:使用编辑器打开nginx/objs/Makefile,删除CFLAGS中的-Werror,如图所示;

image.png

重新进行make操作即可

错误信息2:

    src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
    src/os/unix/ngx_user.c:35:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
         cd.current_salt[0] = ~salt[0];
           ^
    make[1]: *** [objs/Makefile:712: objs/src/os/unix/ngx_user.o] Error 1

原因:源代码问题
解决方法:vim src/os/unix/ngx_user.c

image.png

注释掉蓝线标注的代码
重新make成功

你可能感兴趣的:(nginx 编译安装)