gpt4 book ai didi

php - 在与 Rails 应用程序相同的域中运行 Wordpress 的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 01:20:37 25 4
gpt4 key购买 nike

我有一个标准的 Rails 应用程序,其中包含 Nginx 和 Mongrel,运行于 http://mydomain 。我需要运行一个 WordPress 博客 http://mydomain.com/blog 。我的偏好是在同一服务器或单独的服务器上运行的 Apache 中托管博客,但我不希望用户在 URL 中看到不同的服务器。这可能吗?如果不可能,您会建议采取什么措施来实现这一目标?

最佳答案

实际上,由于您使用的是 Nginx,所以您已经处于良好状态并且不需要 Apache。

您可以通过 fastcgi 运行 PHP(有如何执行此操作的示例 in the Nginx wiki ),并在 Nginx 配置中使用 URL 匹配模式将某些 URL 定向到 Rails,将其他 URL 定向到 PHP。

下面是一个通过 PHP fastcgi 运行 WordPress 博客的 Nginx 配置示例(请注意,我还放入了与 WordPress .htaccess 等效的 Nginx,因此您还将拥有已使用此配置的奇特 URL):

server {
listen example.com:80;
server_name example.com;
charset utf-8;
error_log /www/example.com/log/error.log;
access_log /www/example.com/log/access.log main;
root /www/example.com/htdocs;

include /www/etc/nginx/fastcgi.conf;
fastcgi_index index.php;

# Send *.php to PHP FastCGI on :9001
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001;
}

# You could put another "location" section here to match some URLs and send
# them to Rails. Or do it the opposite way and have "/blog/*" go to PHP
# first and then everything else go to Rails. Whatever regexes you feel like
# putting into "location" sections!

location / {
index index.html index.php;
# URLs that don't exist go to WordPress /index.php PHP FastCGI
if (!-e $request_filename) {
rewrite ^.* /index.php break;
fastcgi_pass 127.0.0.1:9001;
}

}
}

这是我在上面的配置中包含的 fastcgi.conf 文件(我将它放在一个单独的文件中,这样我的所有虚拟主机配置文件都可以将它包含在正确的位置,但您不必这样做):

# joelhardi fastcgi.conf, see http://wiki.codemongers.com/NginxFcgiExample for source
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;

我也碰巧按照 Nginx wiki 的建议进行操作,并使用 Lighttpd 中的 spawn-fcgi 作为我的 CGI-spawner(Lighttpd 的编译速度非常快,没有奇怪的依赖项,因此安装起来既快速又简单),但是您还可以使用简短的 shell/Perl 脚本来实现此目的。

关于php - 在与 Rails 应用程序相同的域中运行 Wordpress 的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/89504/

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