最开始的想法是安装两个nginx,指向不同的端口,后来失败了;
之后想在一个nginx中建两个html文件夹,然后再conf中的server中root指向这两个不同的html文件夹,可是可以,但是静态文件访问不了。
后来想到了用重定向的方式来,两个不同的server的root都指同一个html文件夹,在html文件夹下增加index.php和index_wp.php文件,用于重定向到对应的wordpress项目中
clipboard.png
index.php:
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/blog/wp-blog-header.php' );
index_wp.php:
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define('WP_USE_THEMES', true);
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
conf配置:
blog文件夹对应的conf:
server {
listen 80;
server_name ********; #域名
location / {
index index.php;
}
error_page 502 /error.html;
location = /error.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
wordpress文件夹对应的conf:
这里的location / 中的index 设置为index_wp.php index.php,就会在html目录中先找index_wp.php文件,没有再找index.php文件,之后进入了wordpress文件夹后找不到index_wp.php文件就会接着找index.php文件。如果只设置了index_wp.php的话在进入后台文件是会报403错误
server {
listen 80;
server_name ********;
location / {
index index_wp.php index.php;
}
error_page 502 /error.html;
location = /error.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
这样就可以了!
网友评论