Nginx杂碎

2018-06-22  本文已影响0人  黑客不黑撒

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;

}

上一篇下一篇

猜你喜欢

热点阅读