#Nginx Basics for Ubuntu
To install
sudo apt-get install nginx
Make sure that Apache (if present) is not running. You can only have one listening on port 80.
sudo apachectl stop
To start nginx (Linux)
sudo /etc/init.d/nginx start
To stop nginx (Linux)
sudo /etc/init.d/nginx stop
To reload nginx config (Linux)
sudo /etc/init.d/nginx reload
Location of sites (Linux)
/usr/share/nginx/www/
To check to see if it is running
ps -ef | grep nginx
To edit the nginx Config File
sudo vim /etc/nginx/sites-available/default
##Sample file with virtual sites
http://www.test.com
http://www.example.com
http://www.nodeapp.com
http://localhost
The hosts file can be edited at:
sudo vim /etc/hosts
server {
listen 80;
listen [::]:80;
root /home/www/test.com;
server_name www.test.com;
location / {
index index.htm index.html;
}
}
server {
listen 80;
listen [::]:80;
root /home/www/example.com;
server_name www.example.com;
location / {
index index.htm index.html;
}
}
#Passthrough to node server application
server {
listen 80;
listen [::]:80;
root /home/www/nodeapp.com;
server_name www.nodeapp.com;
location / {
#proxy_pass http://127.0.0.1:3001/api;
proxy_pass http://127.0.0.1:8443;
}
server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible by specifying the wildcard servername
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
}
##Permissions Nginx normally runs under the www-data group. This group needs to have read access to the folder.