bugfix> php > 投稿

3つのシステムがあります。メインはhaproxy(パブリック)で、apacheサーバーが実行されている他の2つのシステム。以下は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 Webサーバーには、WebサイトのPHPコードがあります。ブラウザでWebサイトを開くと、次のエラーが発生しました(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 件
  • ApacheサーバーでCORSを許可する必要があります。

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

    CORSの詳細について:

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

    サーバーにアクセスしない場合は、クロム(私が使用している)の「CORSチェンジャー」などの拡張機能を使用して、ブラウザーで許可することができます。

あなたの答え