首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx everything - 301到子域

nginx everything - 301到子域
EN

Server Fault用户
提问于 2018-06-29 22:35:23
回答 1查看 58关注 0票数 0

我有一些困难,试图将所有的东西转到nginx上的子域。我使用cloudflare运行子域,这就是为什么我需要将流量重定向到这个子域。

*.soldadinhos.global -> site.soldadinhos.global

soldadinhos.global -> site.soldadinhos.global

我该怎么做?

代码语言:javascript
复制
server {
    server_name site.soldadinhos.global;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    root /usr/share/nginx/html;
    include fastcgi.conf;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/soldadinhos.global/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/soldadinhos.global/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 {
   server_name *.soldadinhos.global soldadinhos.global;
   listen 80;
   return 301 https://site.soldadinhos.global;
}

编辑:我修改了conf文件,它现在正在工作,但是如果我访问www.soldadinhos.global/somefile.php,它不会重定向到site.soldadinhos.global/somefile.php。

EN

回答 1

Server Fault用户

发布于 2018-07-02 18:25:23

您可以执行以下操作:

代码语言:javascript
复制
server {
    server_name *.example.com example.com;

    listen 80;

    return 301 http://site.example.com$request_uri;
}

您需要从现有配置中删除example.com

然后,您需要向指向此服务器的DNS添加相应的DNS A记录。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/918916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档