我有我的主站点,假设example.com
(使用ALB + EC2)有两个名为/press
和/diary
(这些站点使用wordpress多站点)的Wordpress站点
由于许多原因,我想创建一个新的Wordpress网站呼叫blog
。
我已经创建了一个在其他ALB和EC2上运行的新站点,它在子域blog.example.com
现在,我想使用example.com/blog
之类的子路径,而不是子域。
我将主站点nginx配置为将对/ blog路径的所有访问权传递给新站点负载均衡器。
mainsite-nginx.conf
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location /healthcheck {
empty_gif;
access_log off;
break;
}
resolver 8.8.8.8;
resolver_timeout 5s;
set $blog_elb "blog-wp-lb-xxx.ap-northeast-1.elb.amazonaws.com";
location @blog {
proxy_pass https://$blog_elb;
}
location ~ ^/blog/?.* {
try_files $uri @blog;
}
if (!-e $request_filename) {
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
location ~* /wp-login\.php|/wp-admin/((?!admin-ajax\.php).)*$ {
fastcgi_pass app:9000;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param HTTPS $my_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass app:9000;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param HTTPS $my_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
新的wordpress网站nginx配置
server {
listen 80;
root /var/www/html;
index index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
set_real_ip_from 10.0.0.0/8;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location /healthcheck {
empty_gif;
access_log off;
break;
}
location ~ /wp-admin/admin-ajax\.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
allow all;
}
location ~ (/wp-admin/.*\.php|wp-login\.php$) {
allow xx.xx.xx.xx/32;
allow xx.xx.xx.xx/32;
allow xx.xx.xx.xx/32;
deny all;
fastcgi_pass wordpress:9000;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Wordpress网站URL设置为https://example.com/blog
我的问题是:
访问https://example.com/blog
时,所有CSS和JS都收到404错误
在浏览器开发人员选项日志中,浏览器似乎尝试访问https://example.com/blog/wp-content/themes/mycustomtheme/css/bootstrap.min.css
它试图获取主服务器上不存在的文件
访问wp-admin页面时,出现重定向循环错误
我该如何解决。
谢谢!