syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
On Linux, Simplest NGINX How to?

I encountered a use case recently that asked me to install a webserver on my laptop.

I studied this page:

https://en.wikipedia.org/wiki/Comparison_of_web_server_software

I decide to install NGINX.

My laptop runs Ubuntu so I ran this shell command to install NGINX:
root@ann15:/home/dan# 
root@ann15:/home/dan# 
root@ann15:/home/dan# aptitude install nginx
The following NEW packages will be installed:
  nginx nginx-common{a} nginx-core{a} 
0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 385 kB of archives. After unpacking 1,320 kB will be used.
Do you want to continue? [Y/n/?] 
Get: 1 http://us.archive.ubuntu.com/ubuntu/ vivid/main nginx-common all 1.6.2-5ubuntu3 [19.9 kB]
Get: 2 http://us.archive.ubuntu.com/ubuntu/ vivid/main nginx-core amd64 1.6.2-5ubuntu3 [361 kB]
Get: 3 http://us.archive.ubuntu.com/ubuntu/ vivid/main nginx all 1.6.2-5ubuntu3 [3,538 B]
Fetched 385 kB in 0s (503 kB/s)
Selecting previously unselected package nginx-common.
(Reading database ... 305144 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.6.2-5ubuntu3_all.deb ...
Unpacking nginx-common (1.6.2-5ubuntu3) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.6.2-5ubuntu3_amd64.deb ...
Unpacking nginx-core (1.6.2-5ubuntu3) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.6.2-5ubuntu3_all.deb ...
Unpacking nginx (1.6.2-5ubuntu3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for ufw (0.34~rc-0ubuntu5) ...
Processing triggers for systemd (219-7ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up nginx-common (1.6.2-5ubuntu3) ...
Processing triggers for ufw (0.34~rc-0ubuntu5) ...
Setting up nginx-core (1.6.2-5ubuntu3) ...
Setting up nginx (1.6.2-5ubuntu3) ...
Processing triggers for systemd (219-7ubuntu6) ...
Processing triggers for ureadahead (0.100.0-19) ...
                            
root@ann15:/home/dan# 
root@ann15:/home/dan# 


root@ann15:/home/dan# 
root@ann15:/home/dan# 
root@ann15:/home/dan# ps -ef | grep nginx
dan       1626  1535  0 20:18 ?        00:00:00 /usr/lib/ibus/ibus-engine-simple
root      3898     1  0 22:46 ?        00:00:00 nginx: master process /usr/sbin/nginx -g
www-data  3899  3898  0 22:46 ?        00:00:00 nginx: worker process                           
www-data  3900  3898  0 22:46 ?        00:00:00 nginx: worker process                           
www-data  3901  3898  0 22:46 ?        00:00:00 nginx: worker process                           
www-data  3902  3898  0 22:46 ?        00:00:00 nginx: worker process                           
root      3992  3255  0 22:50 pts/1    00:00:00 grep --color=auto ngin
At the end of that installation effort I noticed that NGINX processes were running on my laptop.

I used my browser to look for the associated web server:


Next I created a folder named www under my home folder:
mkdir ~/www/
I linked ~/www/ to /var/www/html/ where NGINX could see it:
root@ann15:/home/dan#
root@ann15:/home/dan#
root@ann15:/home/dan# cd /var/www/html
root@ann15:/var/www/html#
root@ann15:/var/www/html# ln -s /home/dan/www .
root@ann15:/var/www/html#
Next, I created a simple HTML file:
dan@ann15:~ $
dan@ann15:~ $
dan@ann15:~ $ cd ~/www/
dan@ann15:~/www $
dan@ann15:~/www $
dan@ann15:~/www $ echo '<html>NGINX says hello world</html>' > hello.html
dan@ann15:~/www $
dan@ann15:~/www $
Then, I checked that NGINX could serve it:
dan@ann15:~/www $
dan@ann15:~/www $ curl localhost:80/www/hello.html
<html>NGINX says hello world</html>
dan@ann15:~/www $
dan@ann15:~/www $
dan@ann15:~/www $
At this point I was happy because I had my laptop in this state:
  • NGINX installed on my laptop
  • NGINX serving HTML from localhost:80
  • A folder where I could put HTML documents which were then served



syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me