Nginx杂碎

Centos7 源码安装 nginx

tar -xzf nginx-1.12.2.tar.gz

cd nginx-1.12.2/

./configure --prefix=/usr/local/nginx --with-http_stub_status_module

make

make install

 

启动/重启/关闭/查看版本

/usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx -s reload

/usr/local/nginx/sbin/nginx -s stop

/usr/local/nginx/sbin/nginx -v

 

修改配置文件

vim /usr/local/nginx/conf/nginx.conf

 

端口转发&负载均衡

upstream hacker {

server 192.168.2.120:7070;

server 192.168.2.120:8080;

server 192.168.2.120:9090;

}

 

server {

location / {

proxy_pass http://hacker;

}

}

 

Nginx静态资源配置

server {

    listen       80;

    server_name  logcenter.cloudcc.com;

    charset utf-8;

    index index.html index.htm index.jsp index.do;

    root /u01/application/log;

    

    #配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。

    location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$

    {

        root /u01/application/log;

        #expires定义用户浏览器缓存的时间为7天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力

        expires      7d;

    }

}

 

 

Nginx域名跳转或代理

server {

        listen       80;

        server_name  logreceiver.cloudcc.com;

        client_max_body_size        100m;

        client_body_buffer_size     128k;

        proxy_connect_timeout       1;

        proxy_send_timeout          1800;

        proxy_read_timeout          1800;

        proxy_buffer_size           4k;

        proxy_buffers               4 32k;

        proxy_busy_buffers_size     64k;

        proxy_temp_file_write_size  64k;

        auth_basic "status";

        location / {

                root   html;

                index  index.html index.htm;

                proxy_next_upstream http_502 http_504 error timeout invalid_header;

                proxy_pass http://logreceiver;

                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

                root   html;

        }

}

 

upstream logreceiver {

        server 172.18.0.3:9017 max_fails=3 fail_timeout=1s;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值