-
Notifications
You must be signed in to change notification settings - Fork 15
Ubuntu Nginx
-
Update apt-get:
sudo apt-get update
-
Install Nginx:
sudo apt-get install nginx
-
Do you want to continue:
Y
-
Add Nginx to Firewall:
a. List of all apps that ufw knows:
sudo ufw app list
i. You should see a list of application profiles including Nginx
b. If SSL is not configured, we only need to allow traffic on port 80 which is Nginx HTTP (Nginx HTTPS is port 443 [ TLS/SSL encrypted]):
sudo ufw allow ‘Nginx HTTP’
c. Verify status:
sudo ufw status
i. You should see HTTP traffic allowed.
-
Check Nginx webserver:
systemctl status nginx
a. Ngnix should be active
-
Test Nginx by typing in your browser:
http://<server_ipaddress>
a. You should get a Welcome to nginx! Page
Here are some common commands used when managing nginx:
- Stop webserver:
sudo systemctl stop nginx
- Start webserver:
sudo systemctl start nginx
- Restart webserver:
sudo systemctl restart nginx
- Reload without dropping connections:
sudo systemctl reload nginx
- To stop Nginx from starting at boot time:
sudo systemctl disable nginx
- To re-enable Nginx to start at boot time:
sudo systemctl enable nginx
Note: This is not recommended for low connectivity deployments. Let's Encrypt needs internet connectivity to renew it's SSL Certificate.
- More Info a. This will work with a specified domain and then we can add Nginx Full to the ufw and not only Nginx HTTP
- Using the sudo account:
sudo nano /etc/nginx/sites-available/default
- Add the following lines:
#### # For security-by-obscurity: stop displaying nginx version
server_tokens off;
set_real_ip_from <server_ip_address>;
set_real_ip_from 127.0.0.1;
#### # This section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream <app_name> {
server 127.0.0.1:8080;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
#### # These two lines, root and index are irrelevant, add index.php to the index if you are using PHP
root /usr/share/nginx/html;
index index.html index.htm index.nginx-debian.html;
#### # Put your domain name
server_name <your_domain>;
access_log /var/log/nginx/meteor.access.log;
error_log /var/log/nginx/meteor.error.log;
proxy_buffers 4 256k;
proxy_buffer_size 128k;
#### # Type this within the location stanza
location \ {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- Save the file and check if there are any errors:
sudo nginx -t
If it is successful... - Restart nginx:
sudo service nginx restart
- Check nginx status:
systemctl status nginx.service
After installing Nginx we'll need to install NodeJS and PM2.