鍍金池/ 問答/Linux/ nginx監(jiān)聽443端口 后面是apache監(jiān)聽8443, apache 返回3

nginx監(jiān)聽443端口 后面是apache監(jiān)聽8443, apache 返回301, nginx 如何正確處理?

nginx監(jiān)聽443,apache監(jiān)聽8443。

nginx配置

server {
  listen 443;
  # server_name *.ht920.com ht920.com;
  server_name www.ht920.com;
  ssl on;
  ssl_certificate   cert/1523974750873.pem;
  ssl_certificate_key  cert/1523974750873.key;
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  location / {
    index index.html index.htm index.php;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://localhost:8443;
  }
  access_log logs/ht920.com_access.log;
}

現(xiàn)象是:
我訪問 https://www.ht920.com/e/admin/ 正常訪問,
訪問 https://www.ht920.com/e/admin 不行,會(huì)跳轉(zhuǎn)到 https://www.ht920.com:8443/e/admin/

我在服務(wù)器訪問了curl -k https://localhost:8443/e/admin
得到結(jié)果是:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://localhost:8443/e/admin/">here</a>.</p>
</body></html>

問題是,我要如何配置,才能正確301跳轉(zhuǎn)?

回答
編輯回答
淡墨

可以在server_name下面這行這個(gè)試試

server {
  listen 443;
  # server_name *.ht920.com ht920.com;
  server_name www.ht920.com;
  server_name_in_redirect off;
  ssl on;
  ssl_certificate   cert/1523974750873.pem;
  ssl_certificate_key  cert/1523974750873.key;
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  location / {
    index index.html index.htm index.php;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://localhost:8443;
  }
  access_log logs/ht920.com_access.log;
}
2018年5月11日 02:09
編輯回答
六扇門

應(yīng)該用proxy_redirect

proxy_redirect https://www.ht920.com:8443/ /;
2017年10月16日 15:28