Linux_Nginx1.18.0_编译安装_第三方模块 nginx-sticky-module-ng

有时我们不想使用系统自带的pcre,zlib,openssl来编译nginx时,可以下载想要的版本的源码来编译。(这种方式下,上面的一些rpm包估计可以简化一些)

pcre-8.35.tar.gz : https://sourceforge.net/projects/pcre/files/pcre/8.35/ 

zlib-1.2.11.tar.gz: https://sourceforge.net/projects/libpng/files/zlib/1.2.11/

OpenSSL_1_0_2q:  https://www.openssl.org/source/old/1.0.2/

    https://github.com/openssl/openssl/releases/tag/OpenSSL_1_0_2q

> ./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/local/sbin  --with-pcre=../other_packages/pcre-8.35  --with-openssl=../other_packages/openssl-1.0.2q  --with-zlib=../other_packages/zlib-1.2.11  --with-stream --with-http_stub_status_module  --with-http_ssl_module  --without-http-gzip_moule --add-module=../other_modules/nginx-sticky-module-ng

--add-module=../other_modules/headers-more-nginx-module

 

 

执行我下面这个脚本就可以啦,编译成自己想要的nginx

echo "开始在Linux操作系统上安装 nginx1.18.0"

chmod -R +x *
echo "解压第三方模块文件(不显示详情解压)"

unzip -o other_modules/nginx-goodies-nginx-sticky-module-ng.zip -d other_modules/ > /dev/null
mv other_modules/nginx-goodies-nginx-sticky-module-ng other_modules/nginx-sticky-module-ng

unzip -o other_modules/nginx_upstream_check_module-master.zip -d other_modules/ > /dev/null
mv other_modules/nginx_upstream_check_module-master other_modules/nginx_upstream_check_module

tar -zxf other_modules/headers-more-nginx-module-0.33.tar.gz -C other_modules/
mv other_modules/headers-more-nginx-module-0.33 other_modules/headers-more-nginx-module

echo "解压依赖包"
tar -zxf other_packages/openssl-1.0.2q.tar.gz -C other_packages/
tar -zxf other_packages/pcre-8.35.tar.gz -C other_packages/
tar -zxf other_packages/zlib-1.2.11.tar.gz -C other_packages/

echo "解压nginx"
tar -zxf nginx-1.18.0.tar.gz

echo "进入目录"
cd nginx-1.18.0

echo "拷贝check模块补丁(它比较特殊)"
patch -p1 < ../other_modules/nginx_upstream_check_module/check_1.16.1+.patch

echo "执行configure"
./configure --prefix=../  --with-pcre=../other_packages/pcre-8.35  --with-openssl=../other_packages/openssl-1.0.2q   --with-zlib=../other_packages/zlib-1.2.11  --with-stream  --without-http_gzip_module  --with-http_stub_status_module  --with-http_ssl_module  --with-threads  --with-file-aio  --with-http_v2_module  --with-http_realip_module  --add-module=../other_modules/nginx-sticky-module-ng  --add-module=../other_modules/headers-more-nginx-module  --add-module=../other_modules/nginx_upstream_check_module

echo ""

echo "编译和安装"

make
make install

echo "编译完成,把生成的文件拷贝到指定目录"
cd ..
mkdir -p nginx_1.18.0_brain/
mv conf/ nginx_1.18.0_brain/
mv html/ nginx_1.18.0_brain/
mv sbin/ nginx_1.18.0_brain/
mv logs/ nginx_1.18.0_brain/
echo "检测安装的详细信息"

./nginx_1.18.0_brain/sbin/nginx -V

echo ""
echo "开机自启动,请手动编辑 /lib/systemd/system/nginx.service,,,内容见具体文档说明"
echo "编辑完成后,手动执行以下两条命令"
echo "sudo systemctl daemon-reload"
echo "sudo systemctl enable nginx.service"

echo "删除临时文件"
rm -rf nginx-1.18.0/
rm -rf other_modules/nginx-sticky-module-ng/
rm -rf other_modules/nginx_upstream_check_module/
rm -rf other_modules/headers-more-nginx-module/
rm -rf other_packages/pcre-8.35/
rm -rf other_packages/openssl-1.0.2q
rm -rf other_packages/zlib-1.2.11

echo "脚本执行完成"

nginx自启动说明

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/sbin/nginx
ExecReload=/usr/local/sbin/nginx -s reload
ExecStop=/usr/local/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

nginx配置文件

#user  root;
worker_processes  4;

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

pid        logs/nginx.pid;

worker_rlimit_nofile  51200;

events {
    use epoll;
    worker_connections  51200;
    multi_accept on;
}

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;
    access_log off;

    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;

    server_tokens off;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32K;
    large_client_header_buffers 4 32K;
    client_max_body_size 100M;

    reset_timedout_connection on;

    #gzip  on;


    upstream route_http_server {
        server 20.198.42.161:30012 max_fails=100 fail_timeout=60;
        keepalive 256;
    }

    server {
        listen       8288;
        listen       8083 ssl;
        server_name  localhost;

        ssl_certificate      ssl/server.crt;
        ssl_certificate_key  ssl/server.key;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

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

        charset utf-8;

        #access_log  logs/host.access.log  main;

        if ($request_method !~* GET|POST) {
           return 403;
        }

      location ~* ^/(iat|istoff|ist8koff|tts|nlp)/{
          proxy_pass http://route_http_server;
          proxy_http_version 1.1;
          proxy_set_header Connection "";
          proxy_set_header Host $host;
          proxy_set_header X-Forward-For $remote_addr;
          proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
      }

      location /proxy/ {
          proxy_pass http://route_http_server;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_http_version 1.1;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $host;
      }

      location /status{
          check_status;
          access_log off;
      }

      location / {
          root html;
          index index.html index.htm;
          proxy_pass http://route_http_server;
          proxy_http_version 1.1;
          proxy_set_header Connection "";
          proxy_next_upstream error timeout http_404 non_idempotent;
     }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.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;
    #    }
    #}

}

ssl目录及其文件放在conf/目录里面即可

 https://files.cnblogs.com/files/xin1006/ssl.zip 

----------- 赠人玫瑰,手有余香     如果本文对您有所帮助,动动手指扫一扫哟   么么哒 -----------


未经作者 https://www.cnblogs.com/xin1006/ 梦相随1006 同意,不得擅自转载本文,否则后果自负
原文地址:https://www.cnblogs.com/xin1006/p/14933931.html