Question

setup domain on magento site

Posted February 16, 2021 165 views
NginxConfiguration ManagementUbuntu 18.04

Hi,
I have a magento2 site on digital ocean http://188.166.112.146/
Setup is Ubuntu 18.04 lts / Nginx

I bought a domain www.ihcare.store and changed the nameserver of domain to ns1.digitalocean.com & ns2.digitalocean.com

Now when I try to browse the website through my domain, www.ihcare.store, it gives 403: forbidden error.

Please help !

PS: I am new to Digital Ocean & Linux environment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
3 answers

Hi @ihcare,

You’ll need to add the domain www.ihcare.store to your Nginx configuration.

In order for Nginx to serve this content, it’s necessary to create a server block with the correct directives. Instead of modifying the default configuration file directly, let’s make a new one at /etc/nginx/sites-available/your_domain:

sudo nano /etc/nginx/sites-available/your_domain

Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:

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

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain www.your_domain;

        location / {
                try_files $uri $uri/ =404;
        }
}

Next, let’s enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Please remember to change the variables your_domain with ihcare.store and the root variable with the document root of your website.

To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file:

sudo nano /etc/nginx/nginx.conf

Find the servernameshashbucketsize directive and remove the # symbol to uncomment the line. If you are using nano, you can quickly search for words in the file by pressing CTRL and w.

...
http {
    ...
    server_names_hash_bucket_size 64;
    ...
}
...

Next, test to make sure that there are no syntax errors in any of your Nginx files:

sudo nginx -t

If there aren’t any problems, restart Nginx to enable your changes:

sudo systemctl restart nginx

Nginx should now be serving your domain name.

Regards,
KFSys

  • Hi,
    Thank you for reply.

    I followed all the steps by you. But now when I browse ihcare.store, it results site not found, while when i browse www.ihcare.store, it downloads a file on computer. While I am able to browse the website using the IP.

Hi @ihcare,

Can you please post your new configuration file in order to make sure everything is configured properly?

I feel like something is being missed that’s really small and just needs to be noticed.

root@ihcareubn184lts:~# sudo nano /etc/nginx/nginx.conf
GNU nano 2.9.3 /etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
workerconnections 768;
# 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;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings