有誰知道 Nginx 中的互動是如何作業的?我目前有一個子域,我們叫它subdomain1,我想把它改成subdomain2。更加具體。我在 docker 容器中運行所有內容,我的證書將用于 subdomain2。并且不會有更多帶有 subdomain1 的服務器。我想保留來自 google 的 subdomain1 的流量,但名稱不再合適,需要更改為 subdomain2。這樣的事情有用嗎?會不會有什么問題?
server {
server_name subdomain1.mydomain.com;
return 301 http://www.subdomain2.mydomain.com/$request_uri;
}
uj5u.com熱心網友回復:
類似的東西可以匹配:
server {
listen 8066;
server_name localhost;
location / {
rewrite (.*)$ http://www.google.com$1 redirect;
}
}
8066 用于我的測驗目的,以重定向到 google.com。如果你嘗試localhost:8066/foo,我會去https://www.google.com/foo
注意那個redirect關鍵字使它成為臨時的。對于永久重定向,請permanent改用。
uj5u.com熱心網友回復:
是的,你的方法會奏效。以下幾點可能會有所幫助:
- 由于您不希望 subdomain1 有任何服務器,但在此重定向中,您需要確保 subdomain1 也指向您托管 subdomain2 的同一服務器
- $方案的使用
server { server_name subdomain1.mydomain.com; return 301 $scheme://subdomain2.mydomain.com$request_uri; } - 通常人們避免在 sub-domain.domain.com 之前使用 www (你也可以參考這個)
uj5u.com熱心網友回復:
nginx 中的部分server有兩個必需的引數listen和server_name. 添加listen到您的配置中,它將起作用
關于服務器的人https://nginx.org/en/docs/http/ngx_http_core_module.html#server
例子
server {
listen 8080;
server_name _;
return 301 http://www.google.com/$request_uri;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/515787.html
標籤:码头工人nginx
