Nginx没有将www重定向到www

所以我这个网站暂时无法透露网址。 因此,我将此问题称为www.example.com。</ p>

我希望任何尝试访问我的网站以重定向到HTTPS :: //www.example.com。 然而,这种情况并非如此。 我设法让它将http重定向到https。</ p>

如果我去example.com它会重定向到www.example.com,但如果我尝试任何其他路由,如 example.com/videos它只是重定向到 https://example.com/videos 而不是 https://www.example.com 。</ p>

这是我的nginx配置文件: </ p>

  server {

listen 80;
server_name example.com www.example.com;
rewrite ^ /(。*)https:// www。 example.com/$1 permanent;
}

server {
listen 443 ssl;

server_name example.com www.thevirtualpornwebsite.com;
root / var / www / example_folder / public;
\ n
index index.php index.html index.htm index.nginx-debian.html;

ssl_certificate /home/example_user/example.com.chained.crt;
ssl_certificate_key / home / example_user / example .com.key;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_serve r_ciphers on;
ssl_ciphers'EECDH + AESGCM:EDH + AESGCM:AES256 + EECDH:AES256 + EDH';

位置/ {
重写^ /(。*)/ $ / $ 1永久物;
try_files $ uri $ uri / /index.php?$query_string;
}

location~ \ .php $ {
include snippets / fastcgi-php.conf;
fastcgi_pass unix:/ run / php / php7 .0-fpm.sock;
}
}
</ code> </ pre>

如果有人能提供帮助那就太棒了!</ p>
</ div>

展开原文

原文

So I a website which i cant reveal the url to at the moment. So i will refer to it as www.example.com for this question.

I want any attempt to get to my site to redirect to HTTPS:://www.example.com. However this is not the case. I have managed to get it working with redirecting http to https.

If i go to example.com it does redirect to www.example.com, but if i try any other route such as example.com/videos it just redirects to https://example.com/videos instead of https://www.example.com.

Here is my nginx config file:

server{

    listen 80;
    server_name example.com www.example.com;
    rewrite ^/(.*) https://www.example.com/$1 permanent;
}

server {
    listen 443 ssl;

    server_name example.com www.thevirtualpornwebsite.com;
    root /var/www/example_folder/public;


    index index.php index.html index.htm index.nginx-debian.html;


    ssl_certificate /home/example_user/example.com.chained.crt;
    ssl_certificate_key /home/example_user/example.com.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


    location / {
        rewrite ^/(.*)/$ /$1 permanent;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
}

If anyone could help out that would be great!

1个回答



如果检查HTTP服务器配置,您应该看到重写规则</ p>

 重写 ^ /(。*)https://www.example.com/$1 permanent; 
</ code> </ pre>

这基本上匹配任何给定的URL,然后将此匹配传递给 新位置作为参数 $ 1 </ code>(检查正则表达式)。</ p>

如果删除此参数,您应该完成所需的操作:</ p>
\ n

 重写^ /。* https://www.example.com/ permanent; 
</ code> </ pre>
</ div>

展开原文

原文

If you check your HTTP server configuration you should see a rewrite rule

rewrite ^/(.*) https://www.example.com/$1 permanent;

This basically matches any given URL and this match is afterwards passed to the new location as the parameter $1 (check regular expressions).

If you remove this parameter, you should accomplish what you want:

rewrite ^/.* https://www.example.com/ permanent;

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问