Nginx使用Laravel反向代理Wordpress
我目前正在管理一个设置,我们在domain.com上使用一个Laravel webapp,在domain.com/blog上运行一个Wordpress博客 domain.com/blog路径被代理到Wordpress博客所在的另一台服务器 设置 服务器1 运行基于Laravel的webapp的nginx Web服务器:Nginx使用Laravel反向代理Wordpress,wordpress,apache,laravel,nginx,reverse-proxy,Wordpress,Apache,Laravel,Nginx,Reverse Proxy,我目前正在管理一个设置,我们在domain.com上使用一个Laravel webapp,在domain.com/blog上运行一个Wordpress博客 domain.com/blog路径被代理到Wordpress博客所在的另一台服务器 设置 服务器1 运行基于Laravel的webapp的nginx Web服务器: server { listen 80; server_name default.com; return 301 https://www.default.c
server {
listen 80;
server_name default.com;
return 301 https://www.default.com$request_uri;
}
server {
listen 443;
ssl_certificate /etc/letsencrypt/live/www.default.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.default.com/privkey.pem;
server_name default.com;
return 301 https://www.default.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
root /var/www/html/default/current/public;
index index.php index.html index.htm;
server_name www.default.com;
error_log /var/log/nginx/www.default.com.error.log debug;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /blog/ {
proxy_pass http://10.2.7.3/blog/;
proxy_set_header Host $host;
}
ssl_certificate /etc/letsencrypt/live/www.default.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.default.com/privkey.pem;
}
服务器2
运行Wordpress的Apache Web服务器:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@default.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
</IfModule>
问题
博客本身工作正常,所有页面都可见,但是wp-admin/重定向到wp-login.php失败
向wp管理员提交CURL请求/
curl https://www.default.com/blog/wp-admin/
< HTTP/1.1 302 Moved Temporarily
< Server: nginx/1.10.1
< Content-Type: text/html; charset=UTF-8
< Location: https://www.default.com/blog/wp-login.php?redirect_to=https%3A%2F%2Fwww.default.com%2Fblog%2Fblog%2Fwp-admin%2F&reauth=1
此呼叫现在由Laravel web应用程序处理,而不是Wordpress博客。这不是应该发生的事情。
这是由nginx配置引起的:
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
为什么该配置会覆盖代理过程?
nginx
根据以下各种规则计算位置
块
要使您的location/blog/
的优先级高于location~\.php$
,请使用^
修饰符:
location ^~ /blog {
proxy_pass http://10.2.7.3;
proxy_set_header Host $host;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ^~ /blog {
proxy_pass http://10.2.7.3;
proxy_set_header Host $host;
}