Ravindra BagaleCourses & study guides

12. Domains and DNS: GoDaddy, Elastic IP, A/CNAME and Subdomains

12.5 Configuring the Web Server for the Domain

DNS visitor la tumchya IP var aanto; aata web server la te naav olakhayla pahije.

# Nginx: /etc/nginx/conf.d/example.conf  (Ubuntu: sites-available/example + symlink)
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example;
    index index.html;
    location / { try_files $uri $uri/ =404; }
}
# Apache: /etc/httpd/conf.d/example.conf  (Ubuntu: sites-available/example.conf + a2ensite)
<VirtualHost *:80>
    ServerName  example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
    <Directory /var/www/example>
        Require all granted
    </Directory>
</VirtualHost>
sudo mkdir -p /var/www/example && echo '<h1>example.com is live!</h1>' | sudo tee /var/www/example/index.html
sudo nginx -t && sudo service nginx reload                  # Nginx
sudo apachectl configtest && sudo service httpd reload      # Apache AL2023/CentOS
sudo apache2ctl configtest && sudo service apache2 reload   # Apache Ubuntu
curl -I http://example.com

If you had put the public IP in server_name in Chapter 8, replace it with the domain names now.

Ravindra Bagale's Tip

Domain chalu zala pan welcome page disto – karan server_name madhe domain nahi. Khup students fakt example.com lihitat aani www visartat. Donhi naave lihaa: server_name yourdomain.com www.yourdomain.com;.

Lab

Create /var/www/yourdomain, add the server block or virtual host, test, reload and open the domain in a browser.