【发布时间】:2018-12-05 00:31:22
【问题描述】:
我有 3 个系统。主要在haproxy(即公共)中,而其他两个运行apache服务器的系统。以下是conf代码sn -p
#---------------------------------------------------------------------
# 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 代码。当我通过浏览器打开网站时,出现以下错误(通过检查元素观察到)
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 中做什么更改?
【问题讨论】:
标签: php linux apache cors haproxy