Skip to content

Just obtained a new SSL certificate, but the browser shows connection is not secure

Solved Hosting
  • Hi, I am using virtualmin and I have obtained new SSL certificate from Let’s Encrypt. And checked the folder, where my domain.conf under the folder “/etc/nginx/sites-enabled”

          ssl_certificate /home/user/ssl.combined;
            ssl_certificate_key /home/user/ssl.key;
    

    They are in the folder listed above. I am not sure what else I shall do to my connection secured.

    Also, I am not sure if I shall open another post or I can ask another question:

    I tried to follow this configuration to deploy my Nginx server. However, the folder is different, my server is not using “/var/www/flarum/public”, rather is “home/user”, when I run, “sudo nginx -t”,

    I believe I should use relative path, but I don’t know how.

    nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/sites-enabled/flarum.conf:51
    nginx: [emerg] directive "ssl_certificate" is not terminated by ";" in /etc/nginx/sites-enabled/flarum.conf:52
    nginx: configuration file /etc/nginx/nginx.conf test failed
    

    And this is the customized the flarum.conf file, I came up with:

    server {
    
      listen [::]:80;
      listen 80;
    
      server_name domain.net;
      return 301 https://$host$request_uri;
      root /var/www/flarum/public;
    
      index index.php;
    
      location / {
        try_files $uri $uri/ /index.php?$query_string;
      }
    
      location ~* \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }
    
            location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
            expires 365d;
            }
    
    
    }
    
    server {
    
            listen 443 ssl;
    
            server_name domain.net;
            root /var/www/flarum/public;
    
            index index.php;
    
            location / {
                    try_files $uri $uri/ /index.php?$query_string;
                    }
    
            location ~* \.php$ {
                    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                    include fastcgi_params;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    }
    
    
            ssl_certificate /etc/nginx/ssl/forum_acehsc_net.pem;
            ssl_certificate_key /etc/nginx/ssl/forum_blank_net.key;
            ssl_prefer_server_ciphers on;
            ssl_buffer_size 4k;
            ssl_ecdh_curve auto;
    
            ## OCSP Stapling
            ssl_stapling on;
            ssl_stapling_verify on;
            resolver 1.1.1.1 valid=300s;
            resolver_timeout 5s;
            ssl_trusted_certificate /etc/nginx/ssl/forum_blank_net.pem;
    
            ssl_session_cache builtin:1000 shared:SSL:10m;
            ssl_session_timeout 10m;
            ssl_session_tickets off;
    
            add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
            add_header Content-Security-Policy "upgrade-insecure-requests" always;
    
            ssl_dhparam /etc/nginx/ssl/dhparam-2048.pem;
    
    
            location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
            expires 365d;
            }
    
    }
    
    
  • @ash3t I just figured out the mistake I made on the previous config. Now the config is working now. Thanks a lot. I couldn’t edit my previous post. Your working copy of the NGINX config really helps. Thanks a lot.

  • @ash3t I’d make several changes here. Enclosed is a working copy of an NGINX config you can base yours on

    server {
    	listen x.x.x.x:443 ssl http2;
    	server_name domain.com www.domain.com;
            include /home/domain/flarum/.nginx.conf;
    	root /home/domain/flarum/public;
    	index index.php index.htm index.html;
    	access_log /var/log/virtualmin/domain.com_access_log;
    	error_log /var/log/virtualmin/domain.com_error_log;
    	fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    	fastcgi_param SERVER_SOFTWARE nginx;
    	fastcgi_param QUERY_STRING $query_string;
    	fastcgi_param REQUEST_METHOD $request_method;
    	fastcgi_param CONTENT_TYPE $content_type;
    	fastcgi_param CONTENT_LENGTH $content_length;
    	fastcgi_param SCRIPT_FILENAME /home/domain/flarum/public$fastcgi_script_name;
    	fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    	fastcgi_param REQUEST_URI $request_uri;
    	fastcgi_param DOCUMENT_URI $document_uri;
    	fastcgi_param DOCUMENT_ROOT /home/domain/flarum/public;
    	fastcgi_param SERVER_PROTOCOL $server_protocol;
    	fastcgi_param REMOTE_ADDR $remote_addr;
    	fastcgi_param REMOTE_PORT $remote_port;
    	fastcgi_param SERVER_ADDR $server_addr;
    	fastcgi_param SERVER_PORT $server_port;
    	fastcgi_param SERVER_NAME $server_name;
    	fastcgi_param PATH_INFO $fastcgi_path_info;
    	fastcgi_param HTTPS $https;
    
            location ~ \.php$  {
    		try_files $uri $fastcgi_script_name =404;
    		fastcgi_pass localhost:8000;
    		#fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    		gzip on;
    		gzip_comp_level 5;
    	}
    
        ssl_certificate /home/domain/ssl.combined;
        ssl_certificate_key /home/domain/ssl.key;
        client_max_body_size 20M;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Download-Options "noopen" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header Content-Security-Policy "upgrade-insecure-requests" always;
        add_header Referrer-Policy 'no-referrer' always;
        add_header Permissions-Policy "accelerometer=(), camera=(), geolocation=(), gyroscope=(), 
        magnetometer=(), microphone=(), payment=(), usb=()" always;
        add_header X-Powered-By "domain" always;
        add_header Access-Control-Allow-Origin "https://domain.com" always;
        add_header X-Permitted-Cross-Domain-Policies "none" always;
        add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
    	if ($scheme = http) {
    		rewrite ^/(?!.well-known)(.*) https://domain.com/$1 permanent;
    	}
    ### redirect www to non-www with client code 301 ###
          if ($host = 'www.domain.com' ) {
             rewrite  ^/(.*)$  https://domain.com/$1  permanent;
          }
    }
    
    
    server {
        if ($host = www.domain.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    	server_name domain.com www.domain.com;
    	listen x.x.x.x;
            return 404; # managed by Certbot
    }
    

    You should not modify the Flarum .nginx conf file, but simply “include” it in your domain.conf

  • @phenomlab Thanks very much for sharing the copy of an NGINX config. I tried to replace the IP and domain with my IP and domain. But it returned with " nginx: configuration file /etc/nginx/nginx.conf test failed" when I save the config file.

    location ~ \.php$  {
    		try_files $uri $fastcgi_script_name =404;
    		fastcgi_pass localhost:8000;
    		#fastcgi_pass unix:/run/php/php8.0-fpm.sock;
    		gzip on;
    		gzip_comp_level 5;
    	}
    

    The previous block is

    location ~ \.php(/|$) {
                    try_files $uri $fastcgi_script_name =404;
                    fastcgi_pass unix:/var/php-nginx/163072439048555.sock/socket;
            }
    

    I am using Php 7.4 should I remain the previous block? I noticed there is php8.0-fpm.sock.

    Then I only changes one line in /etc/nginx/sites-available/mysite01.conf

    include /home/user/public_html/.nginx.conf; 
    
    

    It doesn’t work too. Then my Database lost connection.

  • @ash3t said in Just obtained a new SSL certificate, but the browser shows connection is not secure:

    I am using Php 7.4 should I remain the previous block? I noticed there is php8.0-fpm.sock.

    The command for PHP8.0 is prefix by a hash, so will be ignored.

    Try using fastcgi_pass unix:/run/php/php7.4-fpm.sock; and place a # before the fastcgi_pass localhost:8000; line

    The previous block is

    That socket number is auto assigned to the domain when you create it, so it may make more sense to use that. So, something like this

    location ~ \.php$ {
                    try_files $uri $fastcgi_script_name =404;
                    fastcgi_pass unix:/var/php-nginx/163072439048555.sock/socket;
            }
    

    Or

    location ~ \.php$ {
                    try_files $uri $fastcgi_script_name =404;
                    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
            }
    

    It doesn’t work too. Then my Database lost connection.

    Can you clarify this part ?

  • @Ash3T one other thing that sprung to mind - which mode is PHP running in - FCGID or PHP-FPM ? Shouldn’t make too much difference at this stage, but ideally needs to be PHP-FPM.

  • @phenomlab Thanks very much for your reply. I am really busy these days, and I don’t have time to look more into this. Sorry for the late reply. I will give it a try the other day, and make a note of the details, and keep you posted. Thanks again for your kindness.

    By the way, I cannot use the emoji button, there is no emoji after I click on it. Not sure if this happens to everyone or it is just me.

  • @ash3t There isn’t an emoji button here like there was in Flarum. Is that what you’re referring to, or was it something that used to work, but no longer does ?

  • @phenomlab there is one on my screen, please see this screen shot.

  • @ash3t yes, I see what you mean now. It does appear to be broken. Let me look into that. Meanwhile, you can still use standard ASCII emojis like this one 🙂

  • @phenomlab 😄 Yes. I can send out emoji now.

    I started over and got stuck again, here is my config file, could you please take a look?

    server {
    	server_name domain.com www.domain.com;
    	listen 147.1*2.154.2*3:443;
    	root /home/haobao/public_html;
        index index.php index.htm index.html;
    	access_log /var/log/virtualmin/haobao.gq_access_log;
    	error_log /var/log/virtualmin/haobao.gq_error_log;
    	fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    	fastcgi_param SERVER_SOFTWARE nginx;
    	fastcgi_param QUERY_STRING $query_string;
    	fastcgi_param REQUEST_METHOD $request_method;
    	fastcgi_param CONTENT_TYPE $content_type;
    	fastcgi_param CONTENT_LENGTH $content_length;
    	fastcgi_param SCRIPT_FILENAME /home/haobao/public_html$fastcgi_script_name;
    	fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    	fastcgi_param REQUEST_URI $request_uri;
    	fastcgi_param DOCUMENT_URI $document_uri;
    	fastcgi_param DOCUMENT_ROOT /home/haobao/public_html;
    	fastcgi_param SERVER_PROTOCOL $server_protocol;
    	fastcgi_param REMOTE_ADDR $remote_addr;
    	fastcgi_param REMOTE_PORT $remote_port;
    	fastcgi_param SERVER_ADDR $server_addr;
    	fastcgi_param SERVER_PORT $server_port;
    	fastcgi_param SERVER_NAME $server_name;
    	fastcgi_param PATH_INFO $fastcgi_path_info;
    	fastcgi_param HTTPS $https;
    	fastcgi_split_path_info ^(.+\.php)(/.+)$;
    	location ~ \.php(/|$) {
    		try_files $uri $fastcgi_script_name =404;
    		fastcgi_pass unix:/var/php-nginx/163323042750871.sock/socket;
    	}
        location /cgi-bin/ {
    		gzip off;
    		root /home/haobao/cgi-bin;
    		fastcgi_pass unix:/var/fcgiwrap/163323105555833.sock/socket;
    		fastcgi_param SCRIPT_FILENAME /home/haobao$fastcgi_script_name;
    	}
    	listen 147.1*2.154.2*3:443 ssl;
    	ssl_certificate /home/haobao/ssl.combined;
    	ssl_certificate_key /home/haobao/ssl.key;
    	fastcgi_read_timeout 60;
    }
    

    I tried to add: “/flarum/public/” in the following two places
    root /home/haobao/public_html;
    root /home/haobao/cgi-bin;

    It shows: “403 Forbidden” or "No input file specified. "

  • @ash3t I just figured out the mistake I made on the previous config. Now the config is working now. Thanks a lot. I couldn’t edit my previous post. Your working copy of the NGINX config really helps. Thanks a lot.

  • phenomlabundefined phenomlab has marked this topic as solved on
  • @ash3t Great 🙂 Glad everything has worked out.

  • phenomlabundefined phenomlab unlocked this topic on

Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation💗

  • 2 Votes
    3 Posts
    153 Views

    Just had a look through the new Free NGINX website, which looks like an 80’s throwback and that it was created using a ZX Spectrum 🙂

    https://freenginx.org

    Love the sarcastic note…

    image.png

  • Is nginx necessary to use?

    Moved Solved Hosting
    2
    1 Votes
    2 Posts
    138 Views

    @Panda said in Cloudflare bot fight mode and Google search:

    Basic question again, is nginx necessary to use?

    No, but you’d need something at least to handle the inbound requests, so you could use Apache, NGINX, Caddy… (there are plenty of them, but I tend to prefer NGINX)

    @Panda said in Cloudflare bot fight mode and Google search:

    Do these two sites need to be attached to different ports, and the ports put in the DNS record?

    No. They will both use ports 80 (HTTP) and 443 (HTTPS) by default.

    @Panda said in Cloudflare bot fight mode and Google search:

    Its not currently working, but how would the domain name know which of the two sites to resolve to without more info?
    Currently it only says the IP of the whole server.

    Yes, that’s correct. Domain routing is handled (for example) at the NGINX level, so whatever you have in DNS will be presented as the hostname, and NGINX will expect a match which once received, will then be forwarded onto the relevant destination.

    As an example, in your NGINX config, you could have (at a basic level used in reverse proxy mode - obviously, the IP addresses here are redacted and replaced with fakes). We assume you have created an A record in your DNS called “proxy” which resolves to 192.206.28.1, so fully qualified, will be proxy.sudonix.org in this case.

    The web browser requests this site, which is in turn received by NGINX and matches the below config

    server { server_name proxy.sudonix.org; listen 192.206.28.1; root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy; index index.php index.htm index.html; access_log /var/log/virtualmin/proxy.sudonix.org_access_log; error_log /var/log/virtualmin/proxy.sudonix.org_error_log; location / { proxy_set_header Access-Control-Allow-Origin *; proxy_set_header Host $host; proxy_pass http://localhost:2000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Api-Key $http_x_api_key; } location /images { index index.php index.htm index.html; root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy; } fastcgi_split_path_info "^(.+\.php)(/.+)$"; listen 192.206.28.1:443 ssl http2; ssl_certificate /home/sudonix.org/domains/proxy.sudonix.org/ssl.combined; ssl_certificate_key /home/sudonix.org/ssl.key; }

    The important part here is server_name proxy.sudonix.org; as this is used to “map” the request to the actual domain name, which you can see in the root section as root /home/sudonix.org/domains/proxy.sudonix.org/ogproxy;

    As the DNS record you specified matches this hostname, NGINX then knows what to do with the request when it receives it.

  • VPS Provider

    Solved Hosting
    7
    6 Votes
    7 Posts
    212 Views

    @phenomlab thank you very much. I will use that link when I set up my new server.

    Thanks again!

  • 2 Votes
    3 Posts
    292 Views

    @phenomlab developing an own app is a big time-consuming job, above tool worked perfectly to run quick sample tests.

    i have used temp mail to log in.

    thanks

  • Domain name factors

    Hosting
    16
    1 Votes
    16 Posts
    671 Views

    @phenomlab said in Domain name factors:

    @jac Yes, but don’t forget that Matomo (and most browsers) alike will allow you to “opt out” or not be tracked, so you can’t really rely on these 100%.

    Absolutely, very true pal.

  • DNS record invalid (Google webmaster)

    Solved Hosting
    13
    4 Votes
    13 Posts
    618 Views

    I can confirm the site is now verified and the sitemap has been submitted.

    Thanks chaps @gotwf @phenomlab

  • Virtualmin Letsencrypt Renewal

    Solved Hosting
    13
    1 Votes
    13 Posts
    1k Views

    @gotwf said in Virtualmin Letsencrypt Renewal:

    I favor KISS engineering

    Then I think you’ll be able to appreciate this
    https://content.sudonix.com/keep-it-simple-stupid/

  • 3 Votes
    4 Posts
    429 Views

    @cagatay same here. Was previously an IONOS user, but moved to Hetzner to realise both savings and performance increase and have never looked back.