当我将Angular应用程序与Nginx反向代理一起使用时,主机完全不会更改。它尝试调用路径,但使用相同的url(localhost)。
在/ etc / nginx / servers文件夹中,我有myAppProxy.conf,其配置如下所示。显然,在nginx.conf中,我包含了该路径(包括服务器/*;)。
我从角度将其称为/ ag-rcc-cardcontrols / controls路径,以便nginx代理应重定向到https://whatever.com/ag-rcc-cardcontrols/controls。但是,我收到一个错误响应,可以看到URl是http://localhost/ag-rcc-cardcontrols/controls。
所以,我认为反向代理不起作用。
server {
listen 80 default_server;
root /Users/e1205577/Documents/Workspace/card-controls-rcc-screen/dist/card-controls-rcc-screen;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location /ag-rcc-cardcontrols/ {
# proxy_bind 127.0.0.1;
proxy_pass https://whatever.com;
proxy_pass_request_headers on;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_redirect off;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Strict-Transport-Security "'max-age=31536000; includeSubDomains' always";
proxy_set_header X-Frame-Options "SAMEORIGIN";
proxy_set_header X-XSS-Protection "1; mode=block";
proxy_set_header X-Content-Type-Options "nosniff";
proxy_set_header Referrer-Policy "'strict-origin-when-cross-origin' always";
proxy_set_header Cache-Control "'no-cache, no-store, must-revalidate' always";
proxy_set_header Pragma "no-cache";
}
}
handlePostRequest(url: string) {
url = '/ag-rcc-cardcontrols/controls';
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Accept': 'application/json',
'Client-id': 'client id',
'Application-Id': 'app id',
});
return this.httpClient.post<Object>(url, '{"ignoreRecurring": true}', {'headers': headers}).subscribe(
response => {
console.log(response);
},
(error: HttpErrorResponse) => {
console.log(error);
}
);
}