简体   繁体   English

我无法将 www 重定向到非 WWW 域 nginx

[英]I fail at redirecting www to NON-WWW domain nginx

I try to redirect a www to a non-www site but I am not successful.我尝试将 www 重定向到非 www 站点,但没有成功。 I tried multiple suggestions from other people but I failed.我尝试了其他人的多种建议,但都失败了。 I undid the changes which were suggested on other websites and here is my.CONF:我撤消了其他网站上建议的更改,这是 my.CONF:

 server {
            root /var/www/html/DOMAIN.de;
            index index.php index.html index.htm;
            server_name DOMAIN.de www.DOMAIN.de;

            error_log /var/log/nginx/DOMAIN.de_error.log;
            access_log /var/log/nginx/DOMAIN_access.log;
            client_max_body_size 100M;

            location / {
                  try_files $uri $uri/ /index.php?$args;
            }




            location ~ \.php$ {
                  include snippets/fastcgi-php.conf;
                  fastcgi_pass unix:/run/php/php8.1-fpm.sock;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }

        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/DOMAIN.de/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/DOMAIN.de/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

    }
    server {
        if ($host = DOMAIN.de) {
            return 301 https://$host$request_uri;
        }


            listen 80;
            listen [::]:80;

maybe you have to put it like this:也许你必须这样说:

server {
       listen 80;
       server_name example.com;
       root /var/www/www.example.com/web;

       if ($http_host != "www.example.com") {
                 rewrite ^ http://example.com$request_uri permanent;
       }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM