Nginx源码安装

CentOS7下安装nginx+sticky

1.安装编译环境

安装make:

yum -y install gcc automake autoconf libtool make

安装g++:

yum install gcc-c++

2.安装Nginx依赖包

安装OpenSSL

wget ftp://ftp.openssl.org/source/openssl-1.0.2j.tar.gz

tar zxvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j/
./config --prefix=/usr/local --openssldir=/usr/local/ssl
make && make install

./config shared --prefix=/usr/local --openssldir=/usr/local/ssl
make clean
make && make install

安装zlib库

wget http://zlib.net/zlib-1.2.8.tar.gz

tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure --prefix=/usr/local
make && make install 

安装pcre库

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

tar zxvf pcre-8.39.tar.gz
cd pcre-8.39/
./configure --prefix=/usr/local
make && make install 

3.安装Nginx

wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.0.tar.gz
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
tar zvxf master.tar.gz
mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ nginx-sticky-module
cd nginx-1.10.0/

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/root/pcre-8.39 \
--with-zlib=/root/zlib-1.2.8 \
--with-openssl=/root/openssl-1.0.2j \
--add-module=/root/nginx-sticky-module

make
make install

–with-pcre=/root/pcre-8.39 指的是 pcre-8.39 的源码路径
–with-zlib=/root/zlib-1.2.8 指的是 zlib-1.2.8 的源码路径
–with-openssl=/root/openssl-1.0.2j 指的是 openssl-1.0.2j 的源码路径

4.配置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;
    upstream idap {
        sticky;
        server 10.47.0.96:7080;
        server 10.47.0.96:7070;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass                          http://idap;
            proxy_set_header Host               $host;
            proxy_set_header X-Real-IP          $remote_addr;
            proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        }

        #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;
    #    }
    #}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Stickynginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识名为route (a)客户端首次发起访问请求,nginx接收后,发现请求头没有cookie,则以轮询方式将请求分发给后端服务器。 (b)后端服务器处理完请求,将响应数据返回给nginx。 (c)此时nginx生成带route的cookie,返回给客户端。route的值与后端服务器对应,可能是明文,也可能是md5、sha1等Hash值 (d)客户端接收请求,并保存带route的cookie。 (e)当客户端下一次发送请求时,会带上route,nginx根据接收到的cookie中的route值,转发给对应的后端服务器。 其他需要注意的 (a)同一客户端的请求,有可能落在不同的后端服务器上。如果客户端启动时同时发起多个请求。由于这些请求都没带cookie,所以服务器会随机选择后端服务器,返回不同的cookie。当这些请求中的最后一个请求返回时,客户端的cookie才会稳定下来,值以最后返回的cookie为准。 (b)cookie不一定生效。由于cookie最初由服务器端下发,如果客户端禁用cookie,则cookie不会生效。 (c)客户端可能不带cookie。Android客户端发送请求时,一般不会带上所有的cookie,需要明确指定哪些cookie会带上。如果希望用sticky做负载均衡,请对Android开发说加上cookie。 (d)cookie名称不要和业务使用的cookie重名。Sticky默认的cookie名称是route,可以改成任何值。 (e)客户端发的第一个请求是不带cookie的。服务器下发的cookie,在客户端下一次请求时才能生效。 (f)Nginx sticky模块不能与ip_hash同时使用 sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h] [hash=index|md5|sha1] [no_fallback] [secure] [httponly]; [name=route] 设置用来记录会话的cookie名称 [domain=.foo.bar] 设置cookie作用的域名 [path=/] 设置cookie作用的URL路径,默认根目录 [expires=1h] 设置cookie的生存期,默认不设置,浏览器关闭即失效,需要是大于1秒的值 [hash=index|md5|sha1] 设置cookie中服务器的标识是用明文还是使用md5值,默认使用md5 [no_fallback] 设置该项,当sticky的后端机器挂了以后,nginx返回502 (Bad Gateway or Proxy Error) ,而不转发到其他服务器,不建议设置 [secure] 设置启用安全的cookie,需要HTTPS支持 [httponly] 允许cookie不通过JS泄漏,没用过
安装nginx源码包,您可以按照以下步骤进行操作: 1. 首先,您需要下载nginx源码包。您可以从官方网站上下载最新版本的源码包。您可以在http://nginx.org/download/找到最新的源码包下载链接。 2. 下载完成后,解压源码包。您可以使用tar命令来解压文件。例如,如果您的源码包是nginx-1.20.1.tar.gz,您可以使用以下命令进行解压: ``` tar -zxvf nginx-1.20.1.tar.gz ``` 3. 进入解压后的目录: ``` cd nginx-1.20.1 ``` 4. 在源码目录中,执行configure命令进行配置。该命令将根据您的系统环境进行一些必要的配置: ``` ./configure ``` 5. 配置完成后,运行make命令编译源码: ``` make ``` 6. 编译完成后,运行make install命令将nginx安装到系统中: ``` make install ``` 7. 安装完成后,您可以检查是否成功安装nginx。您可以使用id命令来检查是否存在nginx用户: ``` id nginx ``` 以上就是nginx源码安装的一般步骤。请注意,这里只提供了基本的安装步骤,具体的安装过程可能会因系统环境和配置需求而有所不同。建议您在安装前阅读官方文档或参考更详细的安装指南以确保正确安装nginx。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [nginx源码安装](https://blog.csdn.net/weixin_49185464/article/details/127326489)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值