NGINX HTTPS Configuration Not Working

godwin.oduware nginx-forum at forum.nginx.org
Fri Jun 14 11:45:45 UTC 2019


Hello All,

I am using a Centos 7 OS and I am using nginx for an Angular application. It
was easy configuring nginx to work with http, but when I obtained SSL
certificate, key, etc from Cloudflare and tried to configure nginx to work
with https it didn't work even after trying several solutions provided
online.

I get "The page isn’t redirecting properly" error with the settings below:

/etc/nginx/nginx.conf
----------------------------------
user nginx;
worker_processes auto;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
    # multi_accept on;
}

http {
    ##
    # Basic Settings
    ##

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    server {
        listen 80;
        server_name hero.com;

        return 301 https://$server_name$request_uri;      
    }

    ##
    # Gzip Settings
    ##

    #gzip on;
    #gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    #gzip_types text/plain text/css application/json application/javascript
text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-available/hero.com.conf
--------------------------------------------------------
server {       
    listen 443 ssl;
    include /etc/nginx/snippets/ssl-nohaso.com.conf;
    include /etc/nginx/snippets/ssl-params.conf; 

    server_name nohaso.com;
    location / {
        root /var/www/html/cadastral.nohaso.com;
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }
}

Earlier on when I used the setting below, it goes to the default nginx page
instead of my own page in /var/www/html/hero.com with this message:
"This is the default index.html page that is distributed with nginx on
Fedora. It is located in /usr/share/nginx/html.
You should now put your content in a location of your choice and edit the
root configuration directive in the nginx configuration file
/etc/nginx/nginx.conf."

/etc/nginx/nginx.conf
--------------------------------------------------
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    return 301 https://$host$request_uri;
}

/etc/nginx/sites-available/hero.com.conf
----------------------------------------------------
server {
    listen 80;                
    server_name nohaso.com;
    
    location / {           
        try_files $uri $uri/ /index.html;
    }
}

server {
    listen [::]:443 ssl ipv6only=on;    
    listen 443 ssl;

    server_name nohaso.com;
    root /var/www/html/nohaso.com;

    include /etc/nginx/snippets/ssl-nohaso.com.conf;
    include /etc/nginx/snippets/ssl-params.conf;

    # other vhost configuration    
}
--------------------------------------------------------------------

Please, could someone point me to what I am doing wrong. I want https pages
displayed for the domain and subdomain.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,284532,284532#msg-284532



More information about the nginx mailing list