Answer the question
In order to leave comments, you need to log in
Proxying cross domain requests through nginx unified config?
There is a config for nginx.
The task is to proxy cross-domain ajax requests through your server.
server {
listen 80;
server_name domain.com;
access_log /var/log/nginx/domain.access.log main;
error_log /var/log/nginx/domain.error.log info;
root /var/www;
location ~* ^.*\/proxy\/(?<pschema>.*)?\/(?<phost>.*)?\/.*$ {
set $adr $pschema://$phost;
rewrite ^.*\/proxy\/.*?\/.*?(\/.*)$ $1 break;
proxy_pass http://domain1.com;
# если вот так то не работает
# proxy_pass $adr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $phost;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
proxy_connect_timeout 1;
proxy_intercept_errors on;
expires 30;
break;
}
location / {
index index.html index.htm;
}
location ~* \.(jpg|ico|gif|png|css|js|svg)$ {
access_log off;
expires 30d;
}
}
proxy_pass http://domain1.com;
# если вот так то не работает
# proxy_pass $adr;
server {
listen 80;
server_name domain.com;
access_log /var/log/nginx/domain.access.log main;
error_log /var/log/nginx/domain.error.log info;
root /var/www;
location ~* ^.*\/proxy\/(?<pschema>.*)?\/(?<phost>.*)?\/.*$ {
resolver $dns_from_your_interfaces;
#если есть свой dns на 127.0.0.1 то можно прописать его
set $adr $pschema://$phost;
rewrite ^.*\/proxy\/.*?\/.*?(\/.*)$ $1 break;
proxy_pass $adr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $phost;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
proxy_connect_timeout 1;
proxy_intercept_errors on;
expires 30;
break;
}
location / {
index index.html index.htm;
}
location ~* \.(jpg|ico|gif|png|css|js|svg)$ {
access_log off;
expires 30d;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question