我正在嘗試使用 wordpress 配置 nginx。Apache 服務器在8083 埠上運行。wordpress 網址是https://dhahbya.com
我的 nginx 組態檔是:
server {
listen *:443 ssl;
server_name www.dhahbya.com dhahbya.com;
ssl_certificate ****************;
ssl_certificate_key **************;
location / {
proxy_pass http://127.0.0.1:8083;
}
}
server {
listen 80;
server_name *.dhahbya.com;
return 301 https://$host$request_uri;
}
問題是當我嘗試在網站中導航時,它會將我重定向到 127.0.0.1:8083。
uj5u.com熱心網友回復:
解決方法是洗掉 apache 服務器并將 nginx 配置為運行 wordpress。
uj5u.com熱心網友回復:
根據您在評論中顯示的重定向回應(請在將來使用降價格式發布此類內容):
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 22 Jun 2022 17:27:56 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
X-Redirect-By: WordPress
Location: https://www.dhahbya.com/
此重定向來自 WordPress 核心,最可能的原因是 WordPress 無法檢測到原始請求是使用 HTTPS 協議發出的。X-Forwarded-...通常使用HTTP 標頭可以解決此類問題:
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8083;
}
但是由于一些未知的原因,WordPress 沒有嘗試使用非標準但廣泛使用X-Forwarded-Proto的 HTTP 標頭檢測原始請求方案,is_ssl()WordPress 函式如下所示(在撰寫本文時):
function is_ssl() {
if ( isset( $_SERVER['HTTPS'] ) ) {
if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
return true;
}
if ( '1' == $_SERVER['HTTPS'] ) {
return true;
}
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
return false;
}
非常常見的解決方案是自己將此功能添加到wp-config.php檔案中:
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
}
但是我不喜歡它,因為無需更改 WordPress 檔案就可以實作相同的效果。如果您的上游是使用mod_php模塊的 apache 服務器,則可以HTTPS通過以下方式從 apache 配置中設定該變數:
<IfModule setenvif_module>
SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
</IfModule>
如果你的上游通過 PHP-FPM 使用另一個 nginx 實體為 WordPress 提供服務,你可以使該實體根據HTTP 標頭值HTTPS使用指令設定 FastCGI 變數:fastcgi_paramX-Forwarded-Proto
map $http_x_forwarded_proto $forwarded_https {
https on;
}
server {
...
location ~ \.php$ {
include fastcgi_params;
fastcgi_param HTTPS $forwarded_https if_not_empty;
...
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/495829.html
上一篇:nginx-內容組態檔擴展名
