[英]Redirect www to non-www with Meteor and Meteor UP
如何將www.site.com
上的所有內容重定向到site.com
?
我使用 MUP 將我的應用程序部署到 Digital Ocean。 到目前為止,我正在考慮為 www 添加一個CNAME
(無法使其工作),或者添加一個重定向服務器端的 meteor package(類似於wizonesolutions:canonical ),或者SSH
到服務器中並手動更改NGINX。
這樣做的推薦方法是什么?
我忘了提及我使用SSL (HTTPS)
。 這樣一來,就無法在域設置中使用CNAME
進行重定向。
我無法更改NGINX設置,因為每次部署時,該容器都被替換為一個新容器,而MUP本身對此沒有任何設置。
推薦的非常好的解決方案是使用wizonesolutions:canonical 。 只需記住將mup.js
設置文件中的ROOT_URL
變量設置為所需的URL( https://www.yourdomain.com或https://yourdomain.com )
自 2022 年(mup v1.5.7)起,您可以執行以下操作:
mup.js
proxy: {
domains: 'example.org,www.example.org',
ssl: {
letsEncryptEmail: 'hello@example.org',
forceSSL: true,
},
nginxServerConfig: './nginx.conf',
},
nginx.conf
# Start custom configuration: redirect www to non www
server_name example.org www.example.org;
if ($host = www.example.org) {
return 301 https://example.org$request_uri;
}
# End of custom configuration
Nginx 表示“if is evil”,但這是我發現與自動生成的 nginx 配置互操作的唯一解決方案。
您甚至可以嘗試使用更通用的方法:
server_name ~^.*$;
if ($host ~ ^www\.(?<domain>.+)$) {
return 301 $scheme://$domain$request_uri;
}
在這里,您不必維護任何網站 url。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.