Redirect http to https on nginx

Keywords: WordPress + NGINX + SSL - Google Cloud Platform - Technical issue - Other
bnsupport ID: ac0dd17e-c173-fb67-4ea9-c1295d237f31
Description:
Hi,
I’m trying to redirect http to https and it’s not working…
I modified the /opt/bitnami/nginx/conf/nginx.conf file to include the code below, but it is still not redirecting.

HTTP Server

server {
    # Port to listen on, can also be set in IP:PORT format
    listen  80;
    # Redirect http to https:
    #server_name localhost;
    # return 301 https://$host$request_uri;
    # end redirect
    include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
    location /status {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
        deny all;
    }
    # Cache-control
    location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
    }
}

Could you help me solve this problem?

Thanks

The lines below are without the #. I was unable to edit the topic …
server_name localhost;
return 301 https://$host$request_uri;

Hi @guilesgarcia

Thanks for using Bitnami WordPress + NGINX + SSL!

The lines below are without the #. I was unable to edit the topic …

Are those line also uncommented in your configuration file? According to the report generated by the bnsupport-tool, they seem to be commented:

...
    # HTTP Server
    server {
        # Port to listen on, can also be set in IP:PORT format
        listen  80;
        # Redirect http to https:
	#server_name localhost;
        # return 301 https://$host$request_uri;
        # end redirect
	include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
...

We have this process documented in our guides, have you checked this article with the details?
https://docs.bitnami.com/google/apps/wordpress-pro/administration/force-https-nginx/

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

Thanks for the answer!
I did this in the file (/opt/bitnami/nginx/conf/nginx.conf) now, but it didn’t work! The site is not redirecting http to https.
How can I solve this?

Hi @guilesgarcia

Thanks for the follow-up! I have launched myself a new instance of WordPress + NGINX + SSL and it seems that our guide on how to Force HTTPS Redirection might be outdated.

Here are the steps I followed in order to have it up and running:

  1. You don’t need to perform the previous steps, you may revert them as we won’t be using them:

/opt/bitnami/nginx/conf/nginx.conf

    # HTTP Server
    server {
        # Port to listen on, can also be set in IP:PORT format
        listen  80;
-       # Redirect http to https:
-       server_name localhost;
-       return 301 https://$host$request_uri;
-       # end redirect
        include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
...
    }
  1. Modify the ServerBlock that is in charge of serving HTTP traffic to out WordPress application:

/opt/bitnami/nginx/conf/server_blocks/wordpress-server-block.conf

server {
    # Port to listen on, can also be set in IP:PORT format
    listen 80 default_server;
    root /opt/bitnami/wordpress;
    # Catch-all server block
    # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names
    server_name _;
+   # Redirect http to https:
+   return 301 https://$host$request_uri;
+   # end redirect
...
  1. Check the syntax for NGINX config files is OK and restart NGINX:
$ sudo nginx -t
nginx: the configuration file /opt/bitnami/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/bitnami/nginx/conf/nginx.conf test is successful

$ sudo /opt/bitnami/ctlscript.sh restart nginx

Can you please follow my steps? I’ll let the documentation team know about this once you confirm the changes did work for you :slightly_smiling_face:

Thanks!

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

1 Like

Worked perfectly. Thank you very much!

My pleasure! I have let the documentation team know about this and soon they’ll work on updating the associated guide, thanks for reporting!

If you have any other questions, please do not hesitate to let us know. Feel free to create a new topic referencing this one if necessary.

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart: