在nopCommerce 4.50上使用Nginx启用SSL时出现301循环

klsxnrf1  于 2023-03-17  发布在  Nginx
关注(0)|答案(2)|浏览(122)

我有一个正在工作的Nginx安装,它成功地为index.html提供了SSL,没有任何问题。
当我把它指向同一台机器上我的nopCommerce 4. 50站点时,nopCommerce站点现在使用SSL工作,然而,页面上的所有链接以及资源仍然使用HTTP,Firefox给出了“此页面的部分内容不安全”的警告
为了修复这个问题,我更改了url并在nop设置中启用了SSL。
当我这样做的时候,网站现在无限重定向到它自己。例如,访问https://mynopcommerce.com返回一个301重定向到https://mynopcommerce.com。为了让网站重新工作,我必须手动禁用nop数据库中的SSL。
我已经尝试了www.example.com建议的所有此问题的修复程序https://docs.nopcommerce.com/en/getting-started/advanced-configuration/how-to-install-and-configure-ssl-certification.html#troubleshooting

  • 我已经在appsettings.json中将“UseHttpXForwardedProto”设置为true
  • 我已清除浏览器/服务器/代理cookie和缓存。
  • 我没有使用cloudflare、dns或nginx以外的任何其他代理服务作为反向代理。

我的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向https版本的网站返回301,而不知道它已经在上面了?
这是一个请求过程中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."}}
vfhzx4xs

vfhzx4xs1#

从4.50版本开始,nopCommerce更改了此API。您应该在appSettings.json文件中使用UseProxy选项(设置为true值),而不是UseHttpXForwardedProto

nx7onnlm

nx7onnlm2#

您可以清除ForwardedHeadersOptions中的已知网络和已知代理,或将ASPNETCORE_FORWARDEDHEADERS_ENABLED设置为true,以执行same

相关问题