`
dalan_123
  • 浏览: 87070 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

nginx tcp的使用

阅读更多
安装说明
系统环境:CentOS-6.7
软件:nginx-1.9.9.tar.gz
安装方式:源码编译安装
安装位置:/usr/local/nginx
下载地址:http://nginx.org/en/download.html
安装依赖
yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
下载nginx-1.9.9.tar.gz
wget  http://nginx.org/download/nginx-1.9.9.tar.gz
安装
(1)cd /usr/local
(2)tar -zxvf nginx-1.9.9.tar.gz
(3)cd /usr/local/nginx-1.9.9
(4)./configure \
--prefix=/usr/local/nginx\
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-stream \
--with-stream_ssl_module \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
(5)make
(6)make install
设置nginx.conf文件开启tcp内容如下(/usr/local/nginx/conf下)
stream {
    upstream mssql {
        hash $remote_addr consistent;
        server 10.33.21.252:1433 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
        listen 1433;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass mssql;
    }
}
配置防火墙
vi /etc/sysconfig/iptables
#添加配置
  -A INPUT -m state --state NEW -m tcp -p tcp --dport port(根据实际情况设置) -j ACCEPT
重启防火墙
service iptables restart
启动与测试
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
#查询nginx主进程号
ps -ef | grep nginx
#停止进程
kill -QUIT 主进程号
#快速停止
kill -TERM 主进程号
#强制停止
pkill -9 nginx
重启
/usr/local/nginx/sbin/nginx -s reload
#测试端口
netstat –na|grep (指定配置文件中设定listen的端口)
附加1:configure参数
--help                             print this message

  --prefix=PATH                      setinstallation prefix
  --sbin-path=PATH                   setnginx binary pathname
  --conf-path=PATH                   setnginx.conf pathname
  --error-log-path=PATH              seterror log pathname
  --pid-path=PATH                    setnginx.pid pathname
  --lock-path=PATH                   setnginx.lock pathname

  --user=USER                        setnon-privileged user for
                                     worker processes
  --group=GROUP                      setnon-privileged group for
                                     worker processes

  --build=NAME                       setbuild name
  --builddir=DIR                     setbuild directory

  --with-select_module               enableselectmodule
  --without-select_module            disable selectmodule
  --with-poll_module                 enablepoll module
  --without-poll_module              disable poll module

  --with-threads                     enablethread pool support

  --with-file-aio                    enablefileAIO support
  --with-ipv6                        enableIPv6 support

  --with-http_ssl_module             enablengx_http_ssl_module
  --with-http_spdy_module            enablengx_http_spdy_module
  --with-http_realip_module          enablengx_http_realip_module
  --with-http_addition_module        enablengx_http_addition_module
  --with-http_xslt_module            enablengx_http_xslt_module
  --with-http_image_filter_module    enablengx_http_image_filter_module
  --with-http_geoip_module           enablengx_http_geoip_module
  --with-http_sub_module             enablengx_http_sub_module
  --with-http_dav_module             enablengx_http_dav_module
  --with-http_flv_module             enablengx_http_flv_module
  --with-http_mp4_module             enablengx_http_mp4_module
  --with-http_gunzip_module          enablengx_http_gunzip_module
  --with-http_gzip_static_module     enablengx_http_gzip_static_module
  --with-http_auth_request_module    enablengx_http_auth_request_module
  --with-http_random_index_module    enablengx_http_random_index_module
  --with-http_secure_link_module     enablengx_http_secure_link_module
  --with-http_degradation_module     enablengx_http_degradation_module
  --with-http_stub_status_module     enablengx_http_stub_status_module

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module

  --with-http_perl_module            enablengx_http_perl_module
  --with-perl_modules_path=PATH      setPerl modules path
  --with-perl=PATH                   setperl binary pathname

  --http-log-path=PATH               sethttp access log pathname
  --http-client-body-temp-path=PATH  setpath to store
                                     http client request body temporary files
  --http-proxy-temp-path=PATH        setpath to store
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH      setpath to store
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        setpath to store
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH         setpath to store
                                     http scgi temporary files

  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache

  --with-mail                        enablePOP3/IMAP4/SMTPproxy module
  --with-mail_ssl_module             enablengx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module

  --with-stream                      enableTCP proxy module
  --with-stream_ssl_module           enablengx_stream_ssl_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module

  --with-google_perftools_module     enablengx_google_perftools_module
  --with-cpp_test_module             enablengx_cpp_test_module

  --add-module=PATH                  enablean external module

  --with-cc=PATH                     setC compiler pathname
  --with-cpp=PATH                    setC preprocessor pathname
  --with-cc-opt=OPTIONS              setadditional C compiler options
  --with-ld-opt=OPTIONS              setadditional linker options
  --with-cpu-opt=CPU                 build forthe specified CPU, valid values:
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64

  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage
  --with-pcre=DIR                    setpath to PCRE library sources
  --with-pcre-opt=OPTIONS            setadditional build options forPCRE
  --with-pcre-jit                    build PCRE with JIT compilation support

  --with-md5=DIR                     setpath to md5 library sources
  --with-md5-opt=OPTIONS             setadditional build options formd5
  --with-md5-asm                     use md5 assembler sources

  --with-sha1=DIR                    setpath to sha1 library sources
  --with-sha1-opt=OPTIONS            setadditional build options forsha1
  --with-sha1-asm                    use sha1 assembler sources

  --with-zlib=DIR                    setpath to zlib library sources
  --with-zlib-opt=OPTIONS            setadditional build options forzlib
  --with-zlib-asm=CPU                use zlib assembler sources optimized
                                     forthe specified CPU, valid values:
                                     pentium, pentiumpro

  --with-libatomic                   force libatomic_ops library usage
  --with-libatomic=DIR               setpath to libatomic_ops library sources

  --with-openssl=DIR                 setpath to OpenSSL library sources
  --with-openssl-opt=OPTIONS         setadditional build options forOpenSSL

  --with-debug                       enabledebug logging
-------------------------------------------------------------------------
关于nginx的tcp除了上面的方法;也可以使用nginx_tcp_proxy_module完成
详见:http://www.cnblogs.com/yahue/articles/3792176.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics