NGINX域名阻止www重定向

时间:2016-12-15 11:32:09

标签: php laravel nginx forge

我正在使用laravel forge和nginx,我试图将域名显示为www.example.com而不是example.com

在我帐户的某些旧配置中,我能够在两个版本的网址上显示内容,但是最近我配置网站时重定向了www。版本到根版本。无论如何都要禁用此行为。

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/before/*;
server {
    listen 80;
    listen [::]:80;
    server_name .www.example.com .example.com;
    root /home/forge/example.com/site/web;
    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate
    # ssl_certificate_key
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;
    index index.html index.htm index.php;
    charset utf-8;
    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/example.com/server/*;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    access_log off;
    error_log  /var/log/nginx/example.com-error.log error;
    error_page 404 /index.php;
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    location ~ /\.ht {
        deny all;
    }
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/after/*;

1 个答案:

答案 0 :(得分:1)

您需要使用网址www.example.com而不是example.com创建您的网站,以实现您想要的网址结构。