【问题标题】:Redirect www to non-www with Meteor and Meteor UP使用 Meteor 和 Meteor UP 将 www 重定向到非 www
【发布时间】:2022-04-13 05:52:05
【问题描述】:

如何将www.site.com 上的所有内容重定向到site.com

我使用 MUP 将我的应用程序部署到 Digital Ocean。到目前为止,我正在考虑为 www 添加一个CNAME(无法让它工作),或者添加一个重定向服务器端的流星包(类似于wizonesolutions:canonical),或者SSH 到服务器和@ 987654322@NGINX 手动。

推荐的方法是什么?

【问题讨论】:

  • 转到您的 DNS 设置并设置从 www.site.com 到 site.com 的重定向。这是最简单方便的方法。

标签: redirect meteor nginx meteor-up


【解决方案1】:

我忘了提到我使用SSL (HTTPS)。这样就无法在域设置中使用CNAME 进行重定向。

我无法更改 NGINX 设置,因为每次部署时,容器都会被新容器替换,而 MUP 本身没有任何设置。

推荐的非常好的解决方案是使用wizonesolutions:canonical。请记住将mup.js 设置文件中的ROOT_URL 变量设置为所需的URL(https://www.yourdomain.comhttps://yourdomain.com

【讨论】:

    【解决方案2】:

    截至 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 说“如果是邪恶的”,但这是我发现与自动生成的 nginx 配置互操作的唯一解决方案。

    您甚至可以尝试使用更通用的方法:

    server_name ~^.*$;
    if ($host ~ ^www\.(?<domain>.+)$) {
      return  301 $scheme://$domain$request_uri;
    }
    

    在这里,您无需维护任何网站 url。

    【讨论】:

      猜你喜欢
      • 2016-02-17
      • 2015-11-03
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 2012-10-19
      • 1970-01-01
      相关资源
      最近更新 更多