How to configure SSL on second Multi store site in NGINX server?

2 个月 前
I have a nopCommerce site and we are using multistore functionality-

mysite.com-  this main site is configured on NGINX. Http to https redirection and SSL configuration is done and working fine (we have Let'sEncript wildcard ssl common for subdomains) .
Now I Want to apply https redirection and SSL configuration on second store (sub.mysite.com) using NGINX config settings.

There are very limited information on NGINX configuration for nopCommerce, kindly help.

Current NGINX setting for main store-

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
   '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    
    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;

server {
   listen 80;
   server_name wonderfoodmart.in www.wonderfoodmart.in;
   return 301 https://$server_name$request_uri;
  }
server {
    listen 443 ssl http2 default_server;
        server_name xyz.in www.xyz.in;
        ssl_certificate "/etc/ssl/certs/xyz.in.pem";
        ssl_certificate_key "/etc/ssl/private/xyz.in.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

    location / {
        root /home/xyz/public_html/nop.xyz.in;
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
         client_max_body_size 200M;
    }
}
}
2 个月 前
weworkfromvillage wrote:
I have a nopCommerce site and we are using multistore functionality-

mysite.com-  this main site is configured on NGINX. Http to https redirection and SSL configuration is done and working fine (we have Let'sEncript wildcard ssl common for subdomains) .
Now I Want to apply https redirection and SSL configuration on second store (sub.mysite.com) using NGINX config settings.

There are very limited information on NGINX configuration for nopCommerce, kindly help.

Current NGINX setting for main store-

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
   '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    
    include /etc/nginx/sites-enabled/*.conf;
    server_names_hash_bucket_size 64;

server {
   listen 80;
   server_name wonderfoodmart.in www.wonderfoodmart.in;
   return 301 https://$server_name$request_uri;
  }
server {
    listen 443 ssl http2 default_server;
        server_name xyz.in www.xyz.in;
        ssl_certificate "/etc/ssl/certs/xyz.in.pem";
        ssl_certificate_key "/etc/ssl/private/xyz.in.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

    location / {
        root /home/xyz/public_html/nop.xyz.in;
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
         client_max_body_size 200M;
    }
}
}

Got the solution!
1. For SSL on second store URL, there was an issue in autossl in cpanel, for some domains under wildcard SSL, domain validations were getting failed because default port was changed for NGINX server and validation file (.well-known folder) was inaccessible for domain validations.
Reset the port settings just to run AutoSSL fixed the issue for me.
2. For http to https redirection I used below code in main NGINX conf file-
server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}