СЧАСТЛИВАЯ проблема при интеграции с Apache - PullRequest
0 голосов
/ 26 июня 2018

у меня 3 системы. main в haproxy (это публично), а в двух других системах работает сервер apache. Ниже приведен фрагмент кода conf

#---------------------------------------------------------------------
# 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

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

   default_backend             apache
#Log Format
    log-format %ci:%cp_[%t]_%bi:%bp_%s_%{+Q}r_%ST_%Tq/%Tw/%Tc/%Tr/%Tt_%B
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend apache
    balance     roundrobin
    server      apache40 10.11.12.11:80 check
    server      apache41 10.11.12.12:80 check

На веб-серверах Apache есть некоторый php-код веб-сайта. Когда я открываю сайт через браузер, я получаю следующую ошибку (наблюдается с помощью элемента inspect)

Failed to load http://10.11.12.11/main/assets/redis/new5.php?_=1530007431471: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
(index):1 Failed to load http://10.11.12.11/main/assets/redis/new5.php?_=1530007431472: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

Та же проблема для файлов шрифтов, как показано ниже

Access to Font at 'http://10.11.12.11/main/assets/fonts/fontawesome-webfont.woff?v=4.2.0' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
(index):1 Access to Font at 'http://10.11.12.11/main/assets/fonts/font/nafeesnastaleeqregular1.woff' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
(index):1 Access to Font at 'http://10.11.12.11/main/assets/fonts/fontawesome-webfont.ttf?v=4.2.0' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
(index):1 Access to Font at 'http://10.11.12.11/main/assets/fonts/font/nafeesnastaleeqregular1.ttf' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

Где проблема. Я много искал и пробовал много решений, но замечание сработало для меня. Какие изменения я должен сделать в conf, если таковые имеются?

1 Ответ

0 голосов
/ 26 июня 2018

Вам нужно разрешить CORS на вашем сервере Apache.

https://enable -cors.org / server_apache.html

для получения дополнительной информации о CORS:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Если у вас нет доступа к серверу, вы можете разрешить его в своем браузере, используя расширение, например «CORS changer» для chrome (которое я использую)

...