【发布时间】:2015-06-30 09:03:31
【问题描述】:
在我们的本地开发设置中,我们有一个基于 Angular JS 构建的纯客户端应用程序,它连接到托管在不同服务器上的服务。
为了在我们的开发环境中避免 CORS,我们将 Apache 配置为代理,如下所示
#Apache Configuration
<VirtualHost *:*>
DocumentRoot "../apps"
ProxyPreserveHost On
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyPass /env2/ https://env2-abc.com/
ProxyPassReverse /env2/ https://env2-abc.com/
ServerName localhost:9000
</VirtualHost>
我想为相同的配置设置 nginx,但我遇到了 CORS 问题
#nginx configuration
server {
rewrite_log on;
listen 9090;
server_name localhost;
root ../apps;
index index.html;
location /env2 {
add_header Access-Control-Allow-Origin *;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https:///env2-abc.com;
}
}
谁能帮我正确设置代理和反向代理。到目前为止,apache conf 运行良好,但我想尝试使用 nginx。
提前致谢。
【问题讨论】: