最開始的想法是安裝兩個nginx宴胧,指向不同的端口,后來失敗了;
之后想在一個nginx中建兩個html文件夾肢藐,然后再conf中的server中root指向這兩個不同的html文件夾,可是可以吱韭,但是靜態(tài)文件訪問不了吆豹。
后來想到了用重定向的方式來,兩個不同的server的root都指同一個html文件夾理盆,在html文件夾下增加index.php和index_wp.php文件痘煤,用于重定向到對應的wordpress項目中
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;
}
}
這樣就可以了!