Nginx server config issue

csoftlanka

Well-known member
  • Dec 22, 2017
    476
    442
    63
    Hi elakiriyans.
    mata nginx server ekaka
    http => https
    redirect karanna ona.
    www version url eka handle karanna ona. denata weda karanne https:// abc.com type eka witarai.

    mekata server block use karanna puluwan neda?

    denata virtual host eka tiyanwa sites-available dir eke. ethakota eka edit karanna kalin disable karala inna onada? (similar to Apache)
    methana disable karana kiyanne sym link remove karana ekada?

    me gena danna aya explain karanna poddak. thanks
     

    Sara_LK

    Well-known member
  • Sep 11, 2015
    1,566
    910
    113
    No Place
    certbot daganna eka tama lesima widiha
    vhost hodai
    config eka pahalata me kalla daganna
    server {
    listen 443;
    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_certificate /etc/nginx/ssl/bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/private.key;

    server_name www.example.com;
    access_log /path/to/nginx/accces/log/file;
    error_log /path/to/nginx/error/log/file;

    location / {
    root /var/www/html/yoursite/;
    index index.html;
    }
    }
    server {
    if ($host = example.com) {
    return 301 https://www.example.com$request_uri;
    }

    meken redirect eka wenawa
     
    • Like
    Reactions: csoftlanka

    Djice

    Well-known member
  • Jan 17, 2011
    4,408
    3,776
    113
    out of fucked up land
    have you considered googling?

    this is for redirection
    server { listen 80 default_server; server_name xxx.com; return 301 https://www.xxx.com$request_uri; }

    after editing the file you can do nginx -t to validate the config and then do nginx -s reload to reload config in nginx service

    add another server block for www.xxx.com if you want to handle that domain
     
    Last edited:
    • Like
    Reactions: csoftlanka

    kasun_kbp

    Well-known member
  • May 12, 2015
    18,271
    1
    59,264
    113
    Kaduwela
    Nginx, Apache 🤮
    Litespeed Forever 🤗😽

    image.png
     

    csoftlanka

    Well-known member
  • Dec 22, 2017
    476
    442
    63
    certbot daganna eka tama lesima widiha
    vhost hodai
    config eka pahalata me kalla daganna



    meken redirect eka wenawa
    Thanks for sharing

    have you considered googling?

    this is for redirection
    server { listen 80 default_server; server_name xxx.com; return 301 https://www.xxx.com$request_uri; }

    after editing the file you can do nginx -T to validate the config and then do nginx -s reload to reload config in nginx service

    add another server block for www.xxx.com if you want to handle that domain
    Thanks for sharing
    ------ Post added on Jun 9, 2023 at 1:17 PM

    nginx: [warn] conflicting server name "mysite-web-staging.zillgate.com" on 0.0.0.0:80, ignored
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful


    1st line eke kiyana issue eka hinda VH file eke mokak kalatha effect ekak tibune ne.
    sites-enabled wala tiyna file eke duplicate blocks manually remove kala. (not sure manual method is safe here as cerbot generated content is there)

    ita passe hidden issues left.

    thanks all for your support.
    ------ Post added on Jun 9, 2023 at 1:23 PM