gpt4 book ai didi

php - 如何使用 Nginx VPS 在单个 Ubuntu 实例上设置多个 WordPress 站点

转载 作者:行者123 更新时间:2023-11-29 23:05:53 25 4
gpt4 key购买 nike

我有两个域名(例如 site1.com 和 site2.com),并使用 CNAMES 设置来运行博客(例如 blog.site1.com 和 blog.site2.com)。在一台单独的服务器上,我运行带有 mysql 服务器的 VPS (NGINX) 服务器来运行两个 WordPress 博客。

我能找到的最好的指导是在这个 link 。然而,他们使用的是 Apache 虚拟主机。因此,我使用 Nginx 执行了以下操作:

cd /etc/nginx/sites-available

sudo cp default site1.com
sudo cp default site2.com

在 site1.com 服务器 block 中,我修改了以下内容:

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

#root /usr/share/nginx/html;
root /home/ubuntu/www/blog.site1.com;
index index.php;

server_name blog.site1.com;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php;
}

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

site2.com nginx 服务器 block 也进行了类似的更改。然后为 ~/sites-enabled/文件设置符号链接(symbolic link)。然后我更改了 site1.com 和 site2.com 中每个 WordPress 目录的 wp-config.php。

site1.com (wp-config.php)

/** The name of the database for WordPress */
define('DB_NAME', 'FirstDatabase');

/** MySQL database username */
define('DB_USER', 'FirstUser');

/** MySQL database password */
define('DB_PASSWORD', 'FirstPassword');

site2.com (wp-config.php)

/** The name of the database for WordPress */
define('DB_NAME', 'SecondDatabase');

/** MySQL database username */
define('DB_USER', 'SecondUser');

/** MySQL database password */
define('DB_PASSWORD', 'SecondPassword');

当我导航到 blog.site1.com 或 blog.site2.com 时,我会看到 WordPress 安装页面。

WordPress Installation Page

我完成其中一个 WordPress 站点的安装后出现此问题。尽管我为每个 WordPress 安装实例指定了单独的数据库,但这两个站点都显示相同的 WordPress 实例。由于 wp-config.php 文件清楚地显示了单独的定义,因此我不确定错误在哪里。有人可以提供纠正此问题的指导吗?

最佳答案

Nginx 是一个棘手的野兽。我建议删除 default_server block 并显式指定 IP。我不知道为什么,但根据我的经验,nginx 在使用多个默认服务器或不提供 IP 地址时会变得很奇怪。

我不会直接复制它,因为我的重写条件似乎被那些知道自己在做什么的人皱眉?另外我不使用 fpm。大约有 12 个完全相同的副本,并且所有域加载都没有问题。

server {
listen 198.91.xx.xxx:80;

server_name xxxxxx.org www.xxxxxx.org;

access_log /home/xxxxxx/logs/xxxxxx.org.access.log;
error_log /home/xxxxxx/logs/xxxxxx.org.error.log;

root /home/xxxxxx/domains/xxxxxx.org/public_html/;
index index.php index.html index.htm;

if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}

# serve static files directly
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
expires 30d;
}

#location /indexlocation/ {
# autoindex on;
#}
location ~ .php$ {
fastcgi_pass unix:/tmp/xxxxxx.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

关于php - 如何使用 Nginx VPS 在单个 Ubuntu 实例上设置多个 WordPress 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28292110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com