httpnginxhttpswindows-server

NGINX redirect a http to a https


I'm currently working on redirecting our HTTP website to its HTTPS version. I'm using NGINX on a Windows 10 server and have successfully installed it. However, I'm encountering an issue where I can't seem to locate the correct website. I suspect there might be a problem with my configuration file. I keep getting the "Welcome to nginx!" page instead of the intended webpage. Adding port 8080 to the DNS name works, but we want to access the page using the correct DNS without specifying a port.

The Config file looks like the default one but added these lines (not sure if thats correct):

http {
include       mime.types;
include "C:/SkySpark/var/etc/nginx-1.25.2/nginx-1.25.2/conf/*.conf"
include "C:/SkySpark/var/etc/nginx-1.25.2/nginx-1.25.2/sites-enabled/*"
default_type  application/octet-stream;

Then i've created a new folder named enabled-sites which contains a symlink to the file skyspark.config:

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

  server_name sky****.com; 

  #Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;

  server_name sky****.com; 

  set_real_ip_from 127.0.0.1;
  real_ip_header X-Real-IP;
  real_ip_recursive on;

  #SkySpark Cluster traffic
  location /cluster/ {

    proxy_pass http://127.0.0.1:8080; 

    #IMPORTANT - proxy_pass directive MUST NOT have a trailing /

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }

  #Browser SkySpark traffic
  location / {
    proxy_pass http://127.0.0.1:8080; 
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto http;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  ssl_certificate ****; 
  ssl_certificate_key ****; 

  ssl_session_timeout 10m;
  ssl_session_cache shared:SSL:10m;
  ssl_session_tickets off;

  ssl_protocols TLSv1.3 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DHE+AES128:!aNULL:!eNULL:!LOW;

  gzip on;
  gzip_types text/plain;
  gzip_proxied no-cache no-store private expired auth;
  gzip_min_length 1000;
}

I guess it something with the include lines... If somebody has an idea please let me know!


Solution

  • Sorry, I can't write a comment because this weird site doesn't let you comment without enough reputation.

    Anyways, these are my thoughts:

    Normally you don't have to add the include lines yourself. The sites-enabled folder should already be created and you'll just have to put your config file in the sites-enabled folder without having to edit the root config file. Nginx should find every config file in there by itself.