使用Nginx作为子目录托pipe一个WordPress博客

我有一个现有的meteor应用程序,并使用nginx作为我的服务器,可以在example.com上说

我想添加一个WordPress的博客,应该访问example.com/blog

我最好还是希望我的博客存在于自己的小滴(服务器)上,但是如果它需要在同一个小滴(服务器)上,那就没问题。

我该怎么做呢?

我已经能够在blog.example.com上使用不同server_name的不同服务器块。 我也得到了静态文件,可以在example.com/blog/index.html的子目录下访问。 这一切都存在于同一滴(服务器)上

但是我无法通过example.com/blog访问wordpress应用程序。

编辑:

我最终做的是创build一个新的服务器实例(滴),configuration它与LEMP堆栈和NGINX。 如果我尝试访问IP,它将起作用。

现在,在我的实际服务器上,添加了一个位置块

 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; } 

我的新问题是,我的博客无法加载.css文件在铬合,因为我的代理服务器configuration为HTTPS和WordPress通过HTTP加载文件。 你可以在https://juerix.com/blog查看。

所以我进入了我的wp-config文件,并改变了网站和WordPress的urlhttps://juerix.com/blog 。 没有帮助。

这花了我一段时间的工作。 关键在于try_files行。

 # 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; 

}

这是我发现有用的另一点

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

这是我使用的另一个位置块,只是一个例子

 # 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"; }