Я настроил этот сервер nginx для example.com
и www. example.com
быть кеш / обратный прокси, получение данных с mysource.example.com
Кажется, в браузере все работает нормально, но я заметил значительное падение рейтинга в Google, и когда я протестировал URL с помощью wget, я получил бесконечный цикл.
# test without www , getting infinite loop
wget --header="Host: example.com" http://[SERVER IP]/file.html
Location: https://www.example.com/file.html [following]
--2020-02-07 21:43:14-- https://www.example.com/file.html
Reusing existing connection to www.example.com:443.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.example.com/file.html [following]
20 redirections exceeded.
^^^ RIGHT HERE !!!
# but with www it works OK:
wget --header="Host: www.example.com" http://[SERVER IP]/file.html
HTTP request sent, awaiting response... 200 OK
Length: 1307 (1.3K) [text/plain]
Saving to: ‘file.html’
Думаю, мне нужно указать другой хост
в перенаправлении с не www на www?!
Или это просто wget вещь , потому что обычно она должна переключаться на www.example .com при первом перенаправлении, но он удерживает хост без www от команды nginx?
# redirect http to https
server {
listen 80;
server_name example.com;
server_name www.example.com;
proxy_set_header Host www.example.com
return 301 https://www.example.com$request_uri;
}
# and redirect non www to www
server {
listen 443 ssl http2;
server_name example.com;
proxy_set_header Host www.example.com;
return 301 https://www.example.com$request_uri;
}
# main server, SSL
server {
listen 443 ssl http2;
server_name www.example.com;
location / {
proxy_pass http://mysource.example.com:81;
proxy_set_header Host www.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache nginx_ramdisk_cache;
}
} # end of server
Ny olana dia avy amin'ny fomba fampiasanao wget
. Amin'ny fampiasana:
wget --header="Host: example.com" http://example.com/file.html
soloinao ny lohan'ny mpampiantrano
lohan'ny isaky ny fangatahana wget . Ka:
80
amin'ny mpizara anao ary alefa any amin'ny https://www.example.com/file.html
, 443
an'ny mpizara anao, fa mandefa ny lohateny host Host: example.com
fa tsy Host: www.example.com
. Hiverina any amin'ny https://www.example.com/file.html
, Ka, tsara ny config anao, nisy olana fotsiny ny anao fitsapana. Tsy tokony hihoatra ny lohan'ny host host
ianao, wget dia hametraka azy eo amin'ny sehatra URL ao anaty URL.