2015-09-29 26 views
1

我有1个本地HAProxy的服务器,其用于LOADBALANCE 2个nginx的本地网络服务器((10.10.1.18)web1的 = 10.10.1.21,WEB2 = 10.10.1.22)。Nginx的与共同的haproxy不指向根index.php文件

我能达到Web服务器的本地IPS的index.php文件成功一样,http://10.10.1.21/http://10.10.1.22/

然而,当我点的HAProxy的http://10.10.1.18/本地IP,它不仅带来了的index.html文件代替index.php文件。我们也有一个域名,指向公共IP到haproxy,但http://example.uni.edu再次带来的index.html文件,而不是index.php文件

所以我不认为这是关于公共与本地ip,而是haproxy或nginx配置

/etc/haproxy/haproxy.cfg

 

    #--------------------------------------------------------------------- 
    # Example configuration for a possible web application. See the 
    # full configuration options online. 
    # 
    # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt 
    # 
    #--------------------------------------------------------------------- 

    #--------------------------------------------------------------------- 
    # Global settings 
    #--------------------------------------------------------------------- 
    global 
     # to have these messages end up in /var/log/haproxy.log you will 
     # need to: 
     # 
     # 1) configure syslog to accept network log events. This is done 
     # by adding the '-r' option to the SYSLOGD_OPTIONS in 
     # /etc/sysconfig/syslog 
     # 
     # 2) configure local2 events to go to the /var/log/haproxy.log 
     # file. A line like the following can be added to 
     # /etc/sysconfig/syslog 
     # 
     # local2.*      /var/log/haproxy.log 
     # 
     log   127.0.0.1 local2 

     chroot  /var/lib/haproxy 
     pidfile  /var/run/haproxy.pid 
     maxconn  10000 
     user  haproxy 
     group  haproxy 
     daemon 

     # turn on stats unix socket 
     stats socket /var/lib/haproxy/stats 

    #--------------------------------------------------------------------- 
    # common defaults that all the 'listen' and 'backend' sections will 
    #use if not designated in their block 
    #--------------------------------------------------------------------- 
    defaults 
     mode     http 
     log      global 
     option     httplog 
     option     dontlognull 
     option http-server-close 
     option forwardfor  except 127.0.0.0/8 
     option     redispatch 
     retries     3 
     timeout http-request 10s 
     timeout queue   1m 
     timeout connect   10s 
     timeout client   1m 
     timeout server   1m 
     timeout http-keep-alive 10s 
     timeout check   10s 
     maxconn     10000 


    #--------------------------------------------------------------------- 
    #HAProxy statistics backend 
    #--------------------------------------------------------------------- 
    listen haproxy3-monitoring *:80 
     mode http 
     option forwardfor except 127.0.0.1 
     option httpclose 
     stats enable 
     stats show-legends 
     stats refresh   5s 
     stats uri    /stats 
     stats realm    Haproxy\ Statistics 
     stats auth    username:password 
     stats admin    if TRUE 

    #--------------------------------------------------------------------- 
    # main frontend which proxys to the backends 
    #--------------------------------------------------------------------- 
    frontend main 
      bind *:80 
      default_backend webapp-main 

    # round robin balancing between the various backends 
    #--------------------------------------------------------------------- 
    backend webapp-main 
      balance roundrobin 
      option httpchk HEAD/HTTP/1.1\r\nHost:\ example.uni.edu 
      server web1 10.10.1.21:80 check 
      server web2 10.10.1.22:80 check 

WEB1 nginx的 - /etc/nginx/conf.d/default.conf

 

    server { 
     listen  80; 
     server_name 10.10.1.21; 


     # note that these lines are originally from the "location /" block 
     root /usr/share/nginx/html; 
     index index.php index.html index.htm; 

     location/{ 
      try_files $uri $uri/ =404; 


     } 
     error_page 404 /404.html; 
     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
      root /usr/share/nginx/html; 
     } 


     location ~ [^/]\.php(/|$) { 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      fastcgi_index index.php; 
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
      include   fastcgi_params; 
      fastcgi_param PATH_INFO  $fastcgi_path_info; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     } 

     location /dataroot/ { 
      internal; 
      alias /var/moodledata/; # ensure the path ends with/
     } 

     location /cachedir/ { 
      internal; 
      alias /var/moodledata/cache/; # ensure the path ends with/
     } 


     location /localcachedir/ { 
      internal; 
      alias /var/moodledata/localcache/; # ensure the path ends with/
     } 

     location /tempdir/ { 
      internal; 
      alias /var/moodledata/temp/; # ensure the path ends with/
     } 

     location /filedir/ { 
      internal; 
      alias /var/moodledata/filedir/; # ensure the path ends with/
     } 

    } 

web2与web1具有相同的配置以及自己的本地ip。

当我直接点在index.php http://10.10.1.18/index.php它下载index.php文件,并给出

503服务不可用

任何人有这样类似的经历的问题?

回答

1

最后它的工作,请按照下列步骤操作:

  • 不使用下/etc/nginx/conf.d/配置文件只使用1个配置文件/etc/nginx/nginx.conf这样
 



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

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

     events { 
      worker_connections 8192; 
     } 

     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; 
      tcp_nopush  on; 
      sendfile   on; 
      keepalive_timeout 65; 
      types_hash_max_size 2048; 

      client_body_buffer_size 10K; 
      client_header_buffer_size 1k; 
      client_max_body_size 512m; 
      large_client_header_buffers 2 1k; 

      client_body_timeout 1200; 
      client_header_timeout 1200; 
      send_timeout 100; 

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

     server { 
      listen  80; 
      server_name example.uni.edu; 

      # note that these lines are originally from the "location /" block 
      root /usr/share/nginx/html; 
      index index.php index.html index.htm; 

      location/{ 
       root /usr/share/nginx/html; 
       try_files $uri $uri/ =404; 
       index index.php; 
      } 
      error_page 404 /404.html; 
      error_page 500 502 503 504 /50x.html; 
      location = /50x.html { 
       root /usr/share/nginx/html; 
      } 

      location ~ [^/]\.php(/|$) { 
       root /usr/share/nginx/html; 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_index index.php; 
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 
       #fastcgi_pass 127.0.0.1:9000; 
       include   fastcgi_params; 
       fastcgi_param PATH_INFO  $fastcgi_path_info; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      } 

      ###################### For Moodle Application ################## 
      location /dataroot/ { 
       internal; 
       alias /var/moodledata/; # ensure the path ends with/
      } 

      location /cachedir/ { 
       internal; 
       alias /var/moodledata/cache/; # ensure the path ends with/
      } 


      location /localcachedir/ { 
       internal; 
       alias /var/moodledata/localcache/; # ensure the path ends with/
      } 

      location /tempdir/ { 
       internal; 
       alias /var/moodledata/temp/; # ensure the path ends with/
      } 

      location /filedir/ { 
       internal; 
       alias /var/moodledata/filedir/; # ensure the path ends with/
      } 
      ###################### For Moodle Application ################## 
     } 
     } 

  • 请确保您使用有效的HAProxy的配置有2个不同的端口80一起是后端和8080是监控统计
 

    #--------------------------------------------------------------------- 
    # Example configuration for a possible web application. See the 
    # full configuration options online. 
    # 
    # http://haproxy.1wt.eu/download/1.4/doc/configuration.txt 
    # 
    #--------------------------------------------------------------------- 

    #--------------------------------------------------------------------- 
    # Global settings 
    #--------------------------------------------------------------------- 
    global 
     # to have these messages end up in /var/log/haproxy.log you will 
     # need to: 
     # 
     # 1) configure syslog to accept network log events. This is done 
     # by adding the '-r' option to the SYSLOGD_OPTIONS in 
     # /etc/sysconfig/syslog 
     # 
     # 2) configure local2 events to go to the /var/log/haproxy.log 
     # file. A line like the following can be added to 
     # /etc/sysconfig/syslog 
     # 
     # local2.*      /var/log/haproxy.log 
     # 
     log   127.0.0.1 local2 

     chroot  /var/lib/haproxy 
     pidfile  /var/run/haproxy.pid 
     maxconn  10000 
     user  haproxy 
     group  haproxy 
     daemon 

     # turn on stats unix socket 
     stats socket /var/lib/haproxy/stats 

    #--------------------------------------------------------------------- 
    # common defaults that all the 'listen' and 'backend' sections will 
    #use if not designated in their block 
    #--------------------------------------------------------------------- 
    defaults 
     mode     http 
     log      global 
     option     httplog 
     option     dontlognull 
     option http-server-close 
     option forwardfor  except 127.0.0.0/8 
     option     redispatch 
     retries     3 
     timeout http-request 10s 
     timeout queue   1m 
     timeout connect   10s 
     timeout client   1m 
     timeout server   1m 
     timeout http-keep-alive 10s 
     timeout check   10s 
     maxconn     10000 


    #--------------------------------------------------------------------- 
    #HAProxy statistics backend 
    #--------------------------------------------------------------------- 
    listen haproxy3-monitoring *:8080 
     mode http 
     option forwardfor 
     option httpclose 
     stats enable 
     stats show-legends 
     stats refresh   5s 
     stats uri    /stats 
     stats realm    Haproxy\ Statistics 
     stats auth    username:password 
     stats admin    if TRUE 

    #--------------------------------------------------------------------- 
    # main frontend which proxys to the backends 
    #--------------------------------------------------------------------- 
    frontend main 
      bind *:80 
      option http-server-close 
      option forwardfor 
      default_backend webapp-main 

    # round robin balancing between the various backends 
    #--------------------------------------------------------------------- 
    backend webapp-main 
      balance source 
      option httpchk HEAD/HTTP/1.1\r\nHost:\ example.uni.edu 
      server web1 10.10.1.21:80 check 
      server web2 10.10.1.22:80 check 

您还可以浏览您的应用程序http://example.uni.edu

注意:确保你的公网IP指向你HAProxy的服务器成功!

+0

我有一个错误,当我使用前端主绑定*:80不能绑定0.0。0.0:80但是当我使用8080时,为什么没有错误? –

+0

前端主要 绑定*:80 选项http-server-close 选项转发 default_backend webapp-main –

+0

oppss my bad netstat -anp | grep“:80”使用端口80的nginx:D –

相关问题