大网数据广告活动
服务器运维问答

Hosting a Wordpress Blog using Nginx as sub-directory

· 52CE 我爱测

I have an existing meteor application and am using nginx as my server, lets say at example.com I want to add a wordpress blog, which should be accessed at example.com/blog I also preferably want my blog to exist on it's own dropl…

问题原文

原帖链接 · nupac · CC BY-SA 3.0

I have an existing meteor application and am using nginx as my server, lets say at example.com

I want to add a wordpress blog, which should be accessed at example.com/blog

I also preferably want my blog to exist on it's own droplet (server) but if it needs to be on the same droplet (server) then it's ok.

How do I do this?

I have been able to get it to work with a different server block with a different server_name at blog.example.com. I also have gotten static files to be accessible under a sub directory at example.com/blog/index.html. This where everything exists on the same droplet (server).

But I can't get a wordpress application be accessible through example.com/blog.

EDIT:

What I ended up doing is creating a new server instance(droplet), configured it with LEMP stack and NGINX. It works if I try to access the IP.

Now, on my actual server, added a location block

location /blog {
    rewrite ^/blog/(.*)$ /$1 break;

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://wordpress-server-ip;
    proxy_redirect off;
}

My new problem is, that my blog is not able to load the .css files in chrome because, my proxy server is configured to https and wordpress loads the files over http. You can check this out at https://juerix.com/blog.

So I went into my wp-config file and changed the site and wordpress url https://juerix.com/blog. Didn't help.

已采纳解答

原帖链接 · Tim · CC BY-SA 3.0

This took me a while to work out. The key is in the try_files line.

# Default location to serve
location / {
  # If the file can't be found try adding a slash on the end - it might be
  # a directory the client is looking for. Then try the Wordpress blog URL
  # this might send a few requests to PHP that don't need to go that way
  try_files $uri $uri/ /blog/index.php?$args;

}

Here's another bit I found useful

# Add trailing slash to */wp-admin requests.
rewrite /blog/wp-admin$ $scheme://$host$uri/ permanent;

Here's another location block I used, just as an example

# Rate limit wp-login.php to help prevent brute force attacks
location = /blog/wp-login.php {
  # Next line applies the rate limit defined above
  limit_req zone=login burst=3;
  fastcgi_keep_conn on;

  fastcgi_pass php56-fpm;
  include        fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  more_clear_headers "Cache-Control";
   more_clear_headers Server; more_clear_headers "Pragma"; more_clear_headers "Expires";

  # No caching
  more_clear_headers "Cache-Control";
  add_header Cache-Control "private, max-age=0, no-cache, no-store";
  more_clear_headers "Expires";
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。