我有一个正常工作的 Nginx 安装,它已经成功地使用 SSL 为 index.html 提供服务,没有任何问题。
当我将它指向我在同一台机器上的 nopCommerce 4.50 站点时,nopcommerce 站点现在可以使用 SSL。但是,页面上的所有链接以及资源仍然使用 http,firefox 发出警告“此页面的某些部分不安全”
为了解决这个问题,我更改了 url 并在 nop 设置中启用了 SSL。
当我这样做时,该网站现在无限重定向到自身。例如,访问
https://mynopcommerce.com
返回 301 重定向到 https://mynopcommerce.com
。为了让站点再次运行,我必须在 nop 数据库中手动禁用 SSL。
我的 nginx 服务器块:
server {
listen 443 ssl;
server_name mynopcommerce.com;
ssl_certificate /etc/letsencrypt/live/mynopcommerce.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mynopcommerce.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
proxy_pass http://nopcommerce_web; # DNS resolves name to nop server
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
我相信这可能与 nginx 正在处理 SSL 这一事实有关。在 nop 上启用 SSL 的情况下,nop 和 nginx 之间的非 ssl 通信可能会使 nop 返回 301 到站点的 https 版本,而不知道它已经在上面了?
这是在 1 个请求期间来自 nginx 和 nop 的日志。 (它循环直到出错)
nopcommerce_nginx | [03/Apr/2022:21:07:00 +0000] "GET / HTTP/1.1" 301 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0" "-"
nopcommerce_web | {"EventId":1,"LogLevel":"Information","Category":"Microsoft.AspNetCore.Hosting.Diagnostics","Message":"Request starting HTTP/1.1 GET http://mynopcommerce.com/ - -","State":{"Message":"Request starting HTTP/1.1 GET http://mynopcommerce.com/ - -","Protocol":"HTTP/1.1","Method":"GET","ContentType":null,"ContentLength":null,"Scheme":"http","Host":"mynopcommerce.com","PathBase":"","Path":"/","QueryString":""}}
nopcommerce_web | {"EventId":0,"LogLevel":"Information","Category":"Microsoft.AspNetCore.Routing.EndpointMiddleware","Message":"Executing endpoint \u0027Nop.Web.Controllers.HomeController.Index (Nop.Web)\u0027","State":{"Message":"Executing endpoint \u0027Nop.Web.Controllers.HomeController.Index (Nop.Web)\u0027","EndpointName":"Nop.Web.Controllers.HomeController.Index (Nop.Web)","{OriginalFormat}":"Executing endpoint \u0027{EndpointName}\u0027"}}
nopcommerce_web | {"EventId":3,"LogLevel":"Information","Category":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","Message":"Route matched with {action = \u0022Index\u0022, controller = \u0022Home\u0022, area = \u0022\u0022}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Index() on controller Nop.Web.Controllers.HomeController (Nop.Web).","State":{"Message":"Route matched with {action = \u0022Index\u0022, controller = \u0022Home\u0022, area = \u0022\u0022}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Index() on controller Nop.Web.Controllers.HomeController (Nop.Web).","RouteData":"{action = \u0022Index\u0022, controller = \u0022Home\u0022, area = \u0022\u0022}","MethodInfo":"Microsoft.AspNetCore.Mvc.IActionResult Index()","Controller":"Nop.Web.Controllers.HomeController","AssemblyName":"Nop.Web","{OriginalFormat}":"Route matched with {RouteData}. Executing controller action with signature {MethodInfo} on controller {Controller} ({AssemblyName})."}}
nopcommerce_web | {"EventId":3,"LogLevel":"Information","Category":"Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker","Message":"Authorization failed for the request at filter \u0027Nop.Web.Framework.Mvc.Filters.HttpsRequirementAttribute\u002BHttpsRequirementFilter\u0027.","State":{"Message":"Authorization failed for the request at filter \u0027Nop.Web.Framework.Mvc.Filters.HttpsRequirementAttribute\u002BHttpsRequirementFilter\u0027.","AuthorizationFilter":"Nop.Web.Framework.Mvc.Filters.HttpsRequirementAttribute\u002BHttpsRequirementFilter","{OriginalFormat}":"Authorization failed for the request at filter \u0027{AuthorizationFilter}\u0027."}}