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
The domain is working but the welcome page shows – because the domain isn't in server_name. Many students write only example.com and forget www. Write both names: server_name yourdomain.com www.yourdomain.com;.
Ravindra Bagale's Tip – मराठी
Domain चालू झाला पण welcome page दिसतं – कारण server_name मध्ये domain नाही. बरेच students फक्त example.com लिहितात आणि www विसरतात. दोन्ही नावं लिहा: server_name yourdomain.com www.yourdomain.com;.
Ravindra Bagale's Tip – हिंदी
Domain चल गया पर welcome page दिखता है – क्योंकि server_name में domain नहीं है. बहुत से students सिर्फ़ example.com लिखते हैं और www भूल जाते हैं. दोनों नाम लिखो: 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.