douxian0279 2017-09-15 13:29
浏览 96

nginx两个站点一个目录

I have a project where I want to have one domain per language. So my sites are pointing at the same directory, but for some reason, one of my domains are being redirected to the other.

To clarify. example.com example.org

example.org is pointed to the same directory as example.com.

When I visit example.org, I get redirected to example.com

I don't know if the problem is that I use LetsEncrypt SSL on both domains.

Any clues?

Here is my nginx files

example.com

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;
    root /home/forge/example.com;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /etc/nginx/ssl/example.com/xxx/server.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com/xxx/server.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'XXXXXX-$'
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    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 ~ /(public/mail-signature/.*)$ {

    }

    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.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/after/*;

example.org

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.org/before/*;

server {
    listen 80;
    listen [::]:80;
    server_name example.org;
    root /home/forge/example.com;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl_certificate;
    # ssl_certificate_key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'xxxxxxx-$'
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DOT NOT REMOVE!)
    include forge-conf/example.org/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.org-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.org/after/*;
  • 写回答

1条回答 默认 最新

  • douwei7501 2017-09-15 15:01
    关注

    I would suggest using a more agnostic name for your document root, otherwise is very easy to get confused, you could use something like:

    /home/forge/site-example
    

    Later try to use curl to diagnose your flow, for example:

    curl -I -L https://google.com
    

    The option -I will fetch only headers

    And option -L will follow redirects

    For example for the site http://immortal.run

    $ curl -I -L http://immortal.run
    HTTP/1.1 301 Moved Permanently
    Date: Fri, 15 Sep 2017 14:58:43 GMT
    ...
    
    HTTP/1.1 200 OK
    Date: Fri, 15 Sep 2017 14:58:43 GMT
    Content-Type: text/html; charset=utf-8
    ...
    

    Notice the:

    HTTP/1.1 301 Moved Permanently
    

    That is something probably is happening with your setup.

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况