当前位置: 首页 > 知识库问答 >
问题:

Nginx和haproxy不指向根索引。php文件

罗兴运
2023-03-14

我有一台本地haproxy服务器(10.10.1.18),用于loadbalance 2台nginx本地Web服务器(web1=10.10.1.21,web2=10.10.1.22)。

我可以达到本地IP的web服务器到index.php文件成功http://10.10.1.21/http://10.10.1.22/

但是,当我指向haproxy的本地ip时http://10.10.1.18/,它只带来索引。html文件而不是索引。php文件。我们还有一个域名,它将公共ip指向haproxy,但是http://example.uni.edu再次带来索引。html文件,而不是索引。php文件

所以我不认为这是关于公共ip和本地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。形态


    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。

当我直接指向索引时。phphttp://10.10.1.18/index.php它下载索引。php文件并给出

503服务不可用

有人有类似的经验问题吗?

共有1个答案

唐健
2023-03-14

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

  • 不使用 /etc/nginx/conf.d下的配置文件/只使用一个配置文件 /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配置以及两个不同的端口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://10.10.1.18:8080/或http://example.uni.edu:8080/

你也可以浏览你的申请http://example.uni.edu

注意:确保您的公共ip成功指向haproxy服务器!

 类似资料:
  • 我不认为这是一个复杂的问题,但我没有解决它。 我很乐意指向www.mydomain。com/phpMyAdmin/to/var/www/phpMyAdmin/htdocs/ 我这样做: 但是当调用www.mydomain时,结果是。com/phpMyAdmin是它试图调用的 有人能帮我吗?

  • 我是一个新的拉威尔学习者。在我的Mac(macOS 10.13)上,我配置了Nginx、PHP和MySQL环境。首先,Nginx localhost:8080/laravel/public会毫无问题地显示laravel欢迎页面。但当我尝试添加自定义路线时,例如: 我有404页localhost:8080/laravel/public/test. 在我谷歌了路由404问题的解决方案后,我通过添加 请

  • 这里是MatLab新手(R2015a,MacOS10.10.5),希望能找到解决这个索引问题的方法。 我想基于一个行索引向量和一个列索引向量来更改一个大型2D矩阵的值。举一个非常简单的例子,如果我有一个3 x 2的零矩阵: 我要把A(1,1)=1,而A(2,2)=1,而A(3,1)=1,这样A现在 我想用向量来表示行和列的索引: 有没有办法做到这一点而不循环?请记住,这是一个玩具示例,需要处理非常

  • 这里列示了Apache标准发行版中的所有指令。指令的描述采用统一的格式,其中用到的缩略语在指令术语字典有详细说明。 指令速查以概要形式提供了每个指令的细节。  A  |  B  |  C  |  D  |  E  |  F  |  G  |  H  |  I  |  K  |  L  |  M  |  N  |  O  |  P  |  R  |  S  |  T  |  U  |  V  |  

  • 如果我试图访问网站根目录中不存在的任何内容,即。http://example.com/unexisting.php,我使用以下配置从我的自定义404页面获得正确的好答案: 如果要访问根目录,请尝试访问文件夹。“http://example.com/unexisting_dir/unexisting.php“,404页面在屏幕上,但没有任何图形。因为日志中有“GET/unexisting_dir/i

  • 注意: 我只使用“luceneresults”.ascx和.cs。 ----问题更新了,因为我缩小了问题的范围---- 我试图创建一组特定项的索引,用于Lucene搜索。 在web.config中,我指定了一个索引,该索引包含: 完整索引: