I deplyed two web-server on my machine, one is Apache (port 80
) which launches the PHP5.3, the other one is Nginx (port 8080
) which launches the PHP 7.0.2.
I had made Apache to act as a proxy to Nginx.
I set a VirtualHost of Apache, below is the setting:
<VirtualHost *:80>
ServerAdmin 369273264@qq.com
ServerName wxforum.com
ServerAlias wxforum.com
Header set Access-Control-Allow-Origin "http://wxforum.com"
ErrorLog "/private/var/log/apache2/wxforum.com-error_log"
CustomLog "/private/var/log/apache2/wxforum-access_log" common
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
Below is the partial setting of Nginx:
server {
listen 8080;
server_name localhost;
set $root_path '/usr/local/var/www';
root $root_path;
#index index.php index.html index.htm
#charset koi8-r;
access_log /usr/local/var/log/nginx/localhost.access.log main;
error_log /usr/local/var/log/nginx/localhost.error.log;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$query_string;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root $root_path;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Now When I access http://wxforum.com, the Nginx works, But when I issue an AJAX request, it fails, and shows me:
XMLHttpRequest cannot load http://127.0.0.1:8080/_debugbar/open?op=get&id=9932e2decca12d5f5109a1a61d4ce5dc. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://wxforum.com' is therefore not allowed access.
.
In this case, how could I enable CORS on pure web-server?