How to create a server block
This post explains several steps I have done to get daishodesign.com
up and running on Ubuntu16.04 Nginx web server.
ssh root@xxx.xxx.xx.xxx
Creating directories and change directory in one line. sudo mkdir -p /var/www/daishodesign.com/html && cd /var/www/daishodesign.com/html
In the directory, create a test html file. sudo vim index.html
then write 'Hello world' in it. This is for testing purposes.
*It looks like the last /html
is additional. You can (I guess) omit it if you don't like it.
sudo chown -R $USER:$USER /var/www/daishodesign.com/html
Navigate to /etc/nginx/sites-available/
then create server block file with name of daishodesign.com
*If you have done the same thing before, just copy existing server block file of other site (Say example.com
if there is) to make This step faster. Type cp example.com daishodesign.com
then edit it as shown below.
server {
listen 80;
listen [::]:80;
server_name daishodesign.com www.daishodesign.com;
root /var/www/daishodesign.com/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
error_page 405 =200 $uri;
}
}
Type sudo nginx -t
to test what you've done so far. If everything is okay you'll get this messages.
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart Nginx with sudo systemctl restart nginx
Open new tab in your teminal. It's time to work on your local machine. Make sure there's $
sign at the beginning of your command line which shows you are on local machine. On the other hand, if you see #
sign, you are on remote server so don't do anything crazy.
Check if the site is up and running. Open hosts file by sudo vim /etc/hosts
then add a line xxx.xxx.xx.xxx daishodesign.com www.daishodesign.com
*Replace xxx.xxx.xx.xxx
with your server's IP.
Type http://www.daishodesign.com
in URL. 'Hello world' should be there. If not, go back and check each step carefully.