在我们的本地开发设置中,我们有一个构建在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。
提前谢谢。
发布于 2015-07-02 01:36:47
我可以使用nginx xonf文件中的以下配置来解决上述问题
server {
rewrite_log on;
listen 9000;
server_name localhost;
root ../apps;
index index.html;
access_log off; # I do not need logging in dev env
error_log off; # I do not need logging in dev env
location /env2/ { # trailing / gets substituted by proxy_pass
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_pass https://env2-abc.com/;
}
}https://stackoverflow.com/questions/31133930
复制相似问题