使用Certbot从Nginx删除WWW

时间:2018-06-28 00:41:03

标签: nginx nginx-reverse-proxy

我很困惑,为什么无法让 www 删除该域名。此Nginx配置的底部删除WWW 部分。我不确定 Certbot 是否有任何问题,有人看到这个错误了吗?

该网站已启用,<?php if(isset($_POST['Submit'])){ $username="xxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="shipping_pro"; // Database name $tbl_name="payment_cash"; try { //connection $conn = new PDO('mysql:host=localhost;dbname=shipping_pro', $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $amount = filter_input(INPUT_POST, 'amount'); $sql= "INSERT INTO payment_cash(Amount) VALUES('$amount')"; if ($conn->query($sql)) { echo "<script type=\"text/javascript\"> alert(\"Payment Received Thank You!.\"); window.location = \"../dashboard/index.php\" </script>"; } } catch (PDOException $e) { echo $e->getMessage(); } } ?> www均可正常运行。我正在尝试 www。多年以来我一直没有问过这个问题,我可能会生锈-给锡人加些油!

non www

1 个答案:

答案 0 :(得分:1)

如果您只想使用jesse.red而不是www.jesse.red,则不要在www.jesse.red定义中包含server_name

您的if块不是必需且不正确,因为如果使用$host = www.jesse.red,则return 301 https://$host$request_uri仍为return 301 https://www.jesse.red/$request_uri

您的整体配置可以整理如下:

# Force SSL
server {
    listen 80;
    server_name jesse.red;
    root /var/www/jesse.red/;
    return 301 https://$host$request_uri;
}

# SSL configuration
server {
    listen 443 ssl http2; # managed by Certbot
    gzip off;
    ssl on;

    ssl_certificate /etc/letsencrypt/live/www.jesse.red/fullchain.pem; # managed by Certbot  
    ssl_certificate_key /etc/letsencrypt/live/www.jesse.red/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    error_log /var/www/errors/jesse.red.error.log;

    location / {
        proxy_pass          127.0.0.1:3000;
        #proxy_http_version  1.1;                                                       
        proxy_set_header    Upgrade $http_upgrade;
        proxy_set_header    Connection 'upgrade';
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;
        proxy_cache_bypass  $http_upgrade;
        proxy_read_timeout  90;
    }
}