Nginx

Port Forwarding

  1. install nginx
sudo apt install nginx -y
  1. add our own configuration file
sudo vim /etc/nginx/sites-available/cms_nginx
server {
    listen 80;
   
    location / {
        proxy_pass http://localhost:8888;
    }

    location /admin/ {
        rewrite ^/admin/(.*) /$1 break;
        proxy_pass http://localhost:8889;
    }
    
    location /ranking/ {
        rewrite ^/ranking/(.*) /$1 break;
        proxy_pass http://localhost:8890;
    }
}
  1. create link
sudo ln -s /etc/nginx/sites-available/cms_nginx /etc/nginx/sites-enabled/
  1. test configuration
sudo nginx -t
  1. restart nginx
sudo service nginx restart

Fix Record

413 Request Entity Too Large

/etc/nginx/nginx.conf檔案中找到http段落,加入以下限制

client_max_body_size 100m;

Web Server

server {
   listen 8080;

   root /var/www/html;

   index index.html;

   location / {
       try_files $uri $uri/ =404;
   }
}

如果要改 root directory 的位置,要確保該路徑中的每個資料夾都有+x權限,像是

root /home/contest/website;

要有

sudo chmod +x /home
sudo chmod +x /home/contest

Others

possible path of configuration file
/usr/local/etc/nginx/nginx.conf
/etc/nginx/nginx.conf

events {
    worker_connections  1024;
}

http {
    server {
        listen 80;
        server_name erichung.sa;

        location / {
            proxy_pass http://localhost:8000;
        }
    }
}