Ngnix 配置文件示例-靜態服務器&tcp轉發

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    upstream site {
        server 122.26.157.231:8831;
        server 122.26.157.237:8831;
    } 

    server {
        listen       8000 default_server;
        listen       [::]:8000 default_server;
        server_name  _;
        root         /data/opt/repos;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
             autoindex on;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        listen       2299;
        listen       [::]:2299;
        server_name  location;
        root         /data/opt/repos;

        # 轉載默認配置文件
        include /etc/nginx/default.d/*.conf;
        #端口根路徑映射本地文件夾
        location /{
            root /home/icbcmon/static/;
            autoindex on;
        }
        #錯誤頁面定位轉發
        error_page 404 /404.html;
            location = /40x.html {
        }
    }
}

#轉發流數據
stream {

    upstream mysql {
       hash $remote_addr consistent;
      # $binary_remote_addr;
       server 192.168.182.155:3306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 3306;#數據庫服務器監聽端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;#設置客戶端和代理服務之間的超時時間,如果5分鐘內沒操作將自動斷開。
       proxy_pass mysql;
    }
}

備註: 默認用戶爲ngnix,當權限不足時,可以修改爲root用戶
。本配置文件是在默認的配置文件中進行了追加。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章