试图在nginx上将Http设置为Https重定向

问题描述 投票:-1回答:1

我已经设置好服务器并将项目部署在Vultr VPS上,我试图为我的域设置重定向,但是我一直收到此错误This page isn’t working henryestate.xyz redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS

我已经尝试编辑我的etc/nginx/sites-enabled/default

我有下面的代码:

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  # SSL configuration
  #
  listen 443 ssl;
  # listen [::]:443 ssl default_server;
  #
  # Note: You should disable gzip for SSL traffic.
  # See: https://bugs.debian.org/773332
  #
  # Read up on ssl_ciphers to ensure a secure configuration.
  # See: https://bugs.debian.org/765782
  #
  # Self signed certs generated by the ssl-cert package
  # Don't use them in a production server!
  #
  # include snippets/snakeoil.conf;
  root /var/www/laravel/public;

  # Add index.php to the list if you are using PHP
  index index.php index.html index.htm;

  server_name henryestate.xyz www.henryestate.xyz;

  return 301 https://henryestate.xyz$request_uri;


  ssl_certificate /etc/nginx/ssl/cert_chain.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ /index.php?$query_string;
  }

  # pass PHP scripts to FastCGI server
  #
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    #
    # # With php-fpm (or other unix sockets):
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    # # With php-cgi (or other tcp sockets):
    # fastcgi_pass 127.0.0.1:9000;
  }

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  location ~ /\.ht {
    deny all;
  }
}

如何排序此https重定向,以使www和非www都可以使用https加载网站>

我已经设置了服务器,并在Vultr VPS上部署了项目,并且我试图为我的域设置重定向,但是我一直收到此错误。此页面无法正常运行henryestate.xyz重定向了您...

ssl nginx
1个回答
0
投票
如果您是指从HTTP重定向到HTTPS并保留服务器名称(www或非www),请使用两个不同的server块:
© www.soinside.com 2019 - 2024. All rights reserved.