In this
post, I am going to explain how to serve static page from a file system using
nginx.
Step 1:
Create a directory
'welcome' under root directory.
Create
greet.html and index.html files under welcome directory.
$ls /welcome
greet.html index.html
greet.html
<html>
<head>
<title>Good Day</title>
</head>
<body>
<h1>Good Day Dude!!!!!!</h1>
</body>
</html>
index.html
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Welcome to NGINX</h1>
</body>
</html>
Step 2:
Update
{NGINX_INSTALL_DIRECTORY}/nginx.conf file with below content.
nginx.conf
events { } http { server { listen 9090; server_name localhost; root /welcome; } }
root
/welcome;
‘root’ directive
sets the root directory for requests.
Step 3:
Validate nginx
configuration by executing the command ‘sudo nginx -t’.
$sudo nginx -t
Password:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Step 4:
Reload the nginx
configuration by executing below command.
sudo nginx
-s reload
Open the
url 'http://localhost:9090/' in browser, you can see below screen.
No comments:
Post a Comment