From ElectroDragon
Jump to navigation Jump to search


Remove apache2

  • In case for any error, stop apache first:
sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo apt-get autoremove
  • apt-get install nginx
  • allow gfw -> sudo ufw allow 'Nginx HTTP'
  • Test Welcome to Nginx.png


  • service nginx start
  • check start status -> systemctl status nginx.service
  • systemctl restart nginx
  • Default root folder /var/www/html

Full remove

  • sudo apt-get remove nginx nginx-common # Removes all but config files.
  • sudo apt-get purge nginx nginx-common # Removes everything.
  • sudo apt-get autoremove


  1. Add the sources
sudo echo "
deb jessie all
deb jessie nginx" | sudo tee -a /etc/apt/sources.list

# Add the keys to our system so we trust packages from the sources we added
cd /tmp
sudo apt-key add dotdeb.gpg

sudo apt-key add nginx_signing.key

# finally install nginx
sudo apt update && sudo apt install nginx-full -y


Config sites file

backup site files in sites-available, activatived sites in sites-enabled, creat soft link from sites-available to sites-enabled.

  • default config file: nano /etc/nginx/sites-available/default
  • create soft link to sites-enabled by ls -n /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
  • link enable config file: /etc/nginx/sites-enabled/default
  • delete etc/nginx/sites-avaialble/default
  • edit /etc/nginx/sites-enabled/default
  • set server_name;

Futher Config

Steps Header text Header text
Nginx config /etc/nginx/nginx.conf
Default site config /var/www/html -> defined at /etc/nginx/sites-enabled/default -
  • create file e.g. /etc/ningx/sites-enabled/
  • Optimize -> delete other conf file? FastCGI cache?, gzip missing?


NGINX Config

server {
        listen 80;
        listen [::]:80;

	root /usr/share/nginx/www;  # root of user file
	index index.html index.htm; # file name

	server_name localhost; # e.g.

	location / {
		try_files $uri $uri/ /index.html;

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		deny all;

Setup for uwsgi

server {
        listen 80;


        # root /var/www/html;
        # index index.html;

        location / {
                # try_files $uri $uri/ =404;
                include uwsgi_params; 
                uwsgi_pass unix:/var/www/html/flask-test/sock.sock;


  • /var/log/nginx

Error Fix

upstream prematurely closed connection while reading response header from upstream