将Nginx配置为TCP负载均衡器

前端之家收集整理的这篇文章主要介绍了将Nginx配置为TCP负载均衡器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想使用Nginx 1.9作为TCP负载均衡器.我在https://www.nginx.com/resources/admin-guide/tcp-load-balancing/中遵循了教程,但它没有用.

每当我尝试启动Nginx时,我都会遇到错误

  1. Nginx: [emerg] unknown directive "stream" in /opt/Nginx/Nginx.conf

这是我的Nginx.conf文件

  1. events {
  2. worker_connections 1024;
  3. }
  4. http {
  5. # blah blah blah
  6. }
  7. stream {
  8. upstream backend {
  9. server 127.0.0.1:9630;
  10. server 127.0.0.1:9631;
  11. }
  12. server {
  13. listen 2802;
  14. proxy_connect_timeout 1s;
  15. proxy_timeout 3s;
  16. proxy_pass backend;
  17. }
  18. }

你能告诉我如何配置它吗?

最好的方法是从源代码编译Nginx支持stream指令:

  1. ./configure --prefix=/opt/Nginx --sbin-path=/usr/sbin/Nginx --conf-path=/opt/Nginx/Nginx.conf --pid-path=/var/run/Nginx.pid --lock-path=/var/run/Nginx.lock --with-http_ssl_module --with-threads --with-stream --with-http_slice_module
  2. make
  3. sudo make install

猜你在找的Nginx相关文章