简体   繁体   中英

Redirect from Http to https issue in NGINX Google Compute Engine

We already tried other solutions on Stack Overflow but they didn't work for us.

We are having issues while redirecting our Domain url from http to https .

When we hit the http://example.com , it is not getting redirected to https://example.com . We have also set up a Google Managed SSL in the Load Balancer in our Google Cloud Network Service.

We are using the Google Cloud Compute Engine for hosting the website and Google domains for url. Apart from that we are using the NGINX as our web server and Laravel as our framework. We also contacted the Google support team but couldn't worked.

Front and Backend Load Balancer Configuration:

  • PHP Framework - Laravel V8
  • Compute Engine - Debian 10 Buster

Below is the code for NGINX config file.

NGINX Default Config file


server 
{
   listen 80;

    server_name example.in www.example.in;

    root /var/www/html/test;

    add_header X-Frame-Options "SAMEORIGIN";

    add_header X-XSS-Protection "1; mode=block";

    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {

        try_files $uri $uri/ /index.php?$query_string;

    }

    location = /favicon.ico { access_log off; log_not_found off; }

    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {

        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

        include fastcgi_params;

    }

    location ~ /\.(?!well-known).* {

        deny all;

    }

}

前端配置

后端配置

So the below configuration really solved my issue.

I just added a new Port 80 (Http) configuration in my Front End configuration of my Load Balancer along with the Port 443 (Https).

Now the Domain URL is getting redirected from http to https with secure connections.

Please refer to the below Screenshot of my Load Balancer Frontend Configuration.

负载均衡器前端配置

Thank you @JohnHanley for your answer;)

I think your NGINX configuration needs to adjust to listen on port 443 and you need to get the SSL certificate accordingly. Please refer: https://cloud.google.com/community/tutorials/https-load-balancing-nginx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM