Answer the question
In order to leave comments, you need to log in
How to change the config to add a proxy?
There is a simple file server on NGINX, it just gives files that are in the directory
. You need to add proxying to a specific site.
It would be desirable that when opening the site mysite.ru there were 2 links - like files and redirect.
When opening mysite.ru/files - a file server was opened
When mysite.ru/redirect - let's open google.com
Separately, it's clear, everything works. I do not understand how to push it into 1 config file.
Well, how html needs to be corrected, but it’s already easier, I’ll google it.
server {
listen 80;
listen [::]:80;
server_name site;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# download
autoindex on; # enable directory listing output
autoindex_exact_size off; # output file sizes rounded to kilobytes, megabytes, and gigabytes
#location / {
# root upload;
#}
}
#Вот тут дальше как правильно сделать...
server {
listen 80;
server_name redirect;
location / {
proxy_pass https://www.google.com;
}
}
}
Answer the question
In order to leave comments, you need to log in
You are confusing the terms redirect and proxy. If you need a redirect, then:
location /files {
root /path/to/files/directory;
}
location /google {
return 301 https://www.google.com;
}
location /files {
root /path/to/files/directory;
}
location ~* /google(?<my_uri>.*) {
proxy_set_header Host www.google.com;
proxy_set_header X-Forwarded-Proto https;
proxy_pass https://www.google.com/$my_uri;
proxy_read_timeout 60;
proxy_ssl_name www.google.com;
proxy_ssl_server_name on;
proxy_ssl_session_reuse off;
proxy_redirect off;
}
location / { ... }
, then it will work as expected. curl
, because the browser aggressively caches responses. In particular, if the target server responds with a redirect, then the redirect will be cached, and even if the config ends up working, you'll be left wondering why the result isn't as expected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question