Nginx 基础知识学习

资料

基础

Nginx 性能优化

常用命令

nginx -s stop       快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
nginx -s quit       平稳关闭Nginx,保存相关信息,有安排的结束web服务。
nginx -s reload     因改变了Nginx相关配置,需要重新加载配置而重载。
nginx -s reopen     重新打开日志文件。
nginx -c filename   为 Nginx 指定一个配置文件,来代替缺省的。
nginx -t            不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
nginx -v            显示 nginx 的版本。
nginx -V            显示 nginx 的版本,编译器版本和配置参数。
```

## 反向代理

> 将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称

app.conf:
```
upstream micahel-machine-manager {
    server 100.253.128.222:40012;
    server 100.253.128.223:40012;
}

upstream michael-machine-server {
    server 100.253.128.55:40020;
    server 100.120.128.56:40020;
}

server {
    listen 80;
    server_name michael-api.hw.com;

    client_max_body_size 20M;
    client_body_buffer_size 10M;
    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_next_upstream error timeout invalid_header http_502 http_503 http_504;
    proxy_ignore_client_abort on;
    proxy_read_timeout  180;
    proxy_buffering on;
    proxy_buffer_size 8k;

    proxy_buffers 8 8M;

    gzip                on;
    gzip_min_length     1000;
    gzip_types          text/plain text/css application/json text/xml application/xml application/xml+rss text/javascript;

    location /MachineManager/ {
        proxy_pass http://michael-machine-manager;
    }

    location /MachineServer/ {
        proxy_pass http://michael-machine-server;
    }

	
    access_log /var/log/nginx/cid.hw.com-access.log main;
}
```

如何配置 Nginx 呢?可以利用这个神器:[NginxConfig](https://nginxconfig.io/)
posted @ 2019-03-03 20:05  Michael翔  阅读(215)  评论(0编辑  收藏  举报