1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Access error setuping Multiple Domains in nginx

Discussion in 'Nginx' started by mstdmstd, Mar 12, 2019.

  1. #1
    Hello,
    I try to setup Multiple Domains in nginx under ubuntu 18
    I created new directory with index file:
    mkdir /var/www/test.com
    cd /var/www/test.com
    sudo nano /var/www/test.com.index.html
    Code (markup):
    with some text text
    
    /var/www/test.com.index.html page sample
    
    Code (markup):
    I create config file:
    sudo nano /etc/nginx/modules-available/test.com
    
    Code (markup):
    with text:

    server {
    
    listen 80;
    
    root /var/www/test.com;
    
    index index.html index.htm index.nginx-debian.html;
    
    server_name test.com;
    
    location / {
    try_files $uri $uri/ = 404;
    }
    
    }
    
    Code (markup):
    and in hosts:
    sudo nano /etc/hosts
    Code (markup):
    add 1 line :
    127.0.0.1 localhost test.com
    Code (markup):
    I create symbol link :
    sudo ln -s /etc/nginx/modules-available/test.com /etc/nginx/sites-enabled/

    and Check it I see test.com:
    cd /etc/nginx/sites-enabled/
    ls
    
    sudo service nginx restart
    
    Code (markup):
    check :
    curl test.com [code]
    
    I got :
    $ curl test.com
    [code]<html>
    <head><title>403 Forbidden</title></head>
    <body bgcolor="white">
    <center><h1>403 Forbidden</h1></center>
    <hr><center>nginx/1.14.0 (Ubuntu)</center>
    </body>
    </html>
    
    Code (markup):
    but not sample text I enreed above.

    File /etc/nginx/nginx.conf is default and has lines :
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    Code (markup):
    1) Why error and how to fix it ?

    2) I suppose I need to disable /etc/nginx/sites-available/default file. How can I do it ?
     
    Solved! View solution.
    mstdmstd, Mar 12, 2019 IP
  2. bountysite

    bountysite Active Member

    Messages:
    71
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    73
    #2
    I am assuming that test.com points to your server.
    You need to change the permission of the docroot folder /var/www/test.com to nobody or www-data, whatever is nginx running as.
    
    chown -R  www-data.www-data   /var/www/test.com/
    
    Code (markup):
     
    bountysite, Mar 12, 2019 IP
  3. mstdmstd

    mstdmstd Well-Known Member

    Messages:
    130
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #3
    I run your command and restarting with
    sudo systemctl restart php7.2-fpm
    sudo service nginx restart 
    Code (markup):
    It did not help , I have the same error ...
    Can it be some option or misspelling in modules-available/test.com ?
     
    mstdmstd, Mar 12, 2019 IP
  4. #4
    Check error log for details.
    modules-available or sites-available?
    Did you check what user is nginx running with?
     
    bountysite, Mar 12, 2019 IP
  5. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #5
    Maybe you do not have an index.html file inside the document root.

    `sudo nano /var/www/test.com.index.html` should be `sudo nano /var/www/test.com/index.html`
     
    RoseHosting, Mar 12, 2019 IP
  6. RomanEpo

    RomanEpo Active Member

    Messages:
    127
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    78
    #6
    Please check this...
     
    RomanEpo, Mar 12, 2019 IP