AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 593361
Accepted
Oyabi
Oyabi
Asked: 2014-05-07 03:12:01 +0800 CST2014-05-07 03:12:01 +0800 CST 2014-05-07 03:12:01 +0800 CST

Nginx + php-fpm 和多域

  • 772

我有 3 个域名、1 个服务器和 1 个 IPv4 和 1ipv6。我已经为我的 ipv4 设置了记录(我现在不使用 IPv6)。我的 3 个网站使用 Wordpress。我已经为域配置了 Nginx 和 php-fpm。

/etc/nginx/conf.d/php5-fpm :

upstream php5-fpm-sock {
        server unix:/var/run/php5-fpm.sock; }

/etc/nginx/sites-available/domain.com.conf :

server {
    listen       80;
    server_name  domain.com;

    root /var/www/domain.com;
    index index.php index.html;

    #charset koi8-r;
    access_log  /var/log/nginx/domain.com.access.log;
    error_log /var/log/nginx/domain.com.error.log;

    #include global/common.conf;
    #include global/wordpress.conf;

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

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_pass php5-fpm-sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

/etc/nginx/sites-available/totaly-different-domain.com.conf :

server {
    listen       80;
    server_name  totaly-different-domain.com;

    root /var/www/totaly-different-domain.com;
    index index.php index.html;

    #charset koi8-r;
    access_log  /var/log/nginx/totaly-different-domain.com.access.log;
    error_log /var/log/nginx/totaly-different-domain.com.error.log;


    #include global/common.conf;
    #include global/wordpress.conf;

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

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_index index.php;
                fastcgi_pass php5-fpm-sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }
}

问题:当我输入 domain.com 时域 1 出现在我的导航器上,当我输入 totaly-different-domain.com 时也会出现。

  • domain.com -> 显示 domain.com
  • 完全不同的 domain.com -> 显示 domain.com

PS:我知道我可以优化它,但我想了解为什么我之前遇到过这个问题。

更新 1:

这是我的工作文件:

/etc/nginx/sites-available/domain.com.conf :

server {
    server_name domain.com www.domain.com;

    root /var/www/domain.com/;
    index index.php index.html;

    access_log  /var/log/nginx/domain.com.access.log;
    error_log /var/log/nginx/domain.com.error.log;

    include global/common.conf;
    include global/wordpress.conf;

}

/etc/nginx/sites-available/totaly-different-domain.com.conf :

server {
    server_name totaly-different-domain.com www.totaly-different-domain.com;

    root /var/www/totaly-different-domain.com/;
    index index.php index.html;

    access_log  /var/log/nginx/totaly-different-domain.com.access.log;
    error_log /var/log/nginx/totaly-different-domain.com.error.log;

    include global/common.conf;
    include global/wordpress.conf;

}

/etc/nginx/global/common.conf :

# Global configuration file.
# ESSENTIAL : Configure Nginx Listening Port
listen 80;

# ESSENTIAL : Default file to serve. If the first file isn't found,
index index.php index.html index.htm;

# ESSENTIAL : no favicon logs
location = /favicon.ico {
    log_not_found off;
    access_log off;
}

# ESSENTIAL : robots.txt
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

# ESSENTIAL : Configure 404 Pages
error_page 404 /404.html;

# ESSENTIAL : Configure 50x Pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/www;
}

# SECURITY : Deny all attempts to access hidden files .abcde
location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
}

# PERFORMANCE : Set expires headers for static files and turn off logging.
location ~* ^.+\.(js|css|swf|xml|txt|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|$
    access_log off;
    log_not_found off;
    expires 30d;
}

/etc/nginx/global/wordpress.conf :

# WORDPRESS : Rewrite rules, sends everything through index.php and keeps the a$
location / {
    try_files $uri $uri/ /index.php?$args;
}

# SECURITY : Deny all attempts to access PHP Files in the uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

# REQUIREMENTS : Enable PHP Support
location ~ \.php$ {
    # SECURITY : Zero day Exploit Protection
    try_files $uri =404;

    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php5-fpm-sock;

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}
nginx
  • 2 2 个回答
  • 3774 Views

2 个回答

  • Voted
  1. Best Answer
    Oyabi
    2014-05-07T12:26:28+08:002014-05-07T12:26:28+08:00

    好的,我找到了解决方案。您必须更换:

    server_name totaly-different-domain.com;
    

    经过

    server_name totaly-different-domain.com www.totaly-different-domain.com;
    

    domain.com 也是一样。

    • 0
  2. mjmcull
    2014-05-08T07:57:11+08:002014-05-08T07:57:11+08:00

    你不需要更换

         server_name totaly-different-domain.com;
    

    和

         server_name totaly-different-domain.com www.totaly-different-domain.com;
    

    使用您发布的配置,我无法重现您的问题。您的问题与您的配置无关。

    尝试暂时将 index.php 的内容替换为

       <?php echo $_SERVER['SERVER_NAME']; ?>
    

    并访问每个站点。如果为每个域显示正确的服务器名称,您可能会发现此链接很有帮助。http://tommcfarlin.com/resolving-the-wordpress-multisite-redirect-loop/

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve