Difference between revisions of "Set up Nginx as a Reverse Proxy"

From PKC
Jump to navigation Jump to search
BenKoo>Admin
m (1 revision imported)
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The first place to learn Nginx can be found in this book<ref>eJonghe, D. (2017). NGINX cookbook : advanced recipes for operations(First edition. ed., pp. 1 online resource (1 volume)). Retrieved from https://go.oreilly.com/massachusetts-institute-of-technology-mit/library/view/-/9781492049098/?ar</ref>:
#REDIRECT [[Nginx as a Reverse Proxy]]
 
=Install Nginx=
The following code can be copied and pasted to perform the task of installing Nginx on Ubuntu:<ref>Edward S., How to Set Up an Nginx Reverse Proxy, Retrieved from https://www.hostinger.com/tutorials/how-to-set-up-nginx-reverse-proxy/</ref>
<syntaxhighlight>
sudo apt-get update
sudo apt-get install nginx -y
</syntaxhighlight>
 
=Disable Default Virtual Host of Nginx=
Then, try to unlink this existing link:
<syntaxhighlight>
sudo unlink /etc/nginx/sites-enabled/default
</syntaxhighlight>
 
=Create the Reverse Proxy=
Now go to the Nginx site-available directory
<syntaxhighlight>
cd /etc/nginx/sites-available
</syntaxhighlight>
 
Use a text editor or copy a file with the following file name: <code>reverse-proxy.conf</code>.
 
For example:
<syntaxhighlight>
vi reverse-proxy.conf
</syntaxhighlight>
 
Use a text editor or copy a file with the following file name: <code>reverse-proxy.conf</code>.
 
For example, use the text editor vi, you can type the following command:
<syntaxhighlight>
vi reverse-proxy.conf
</syntaxhighlight>
 
 
In the file, type in the following content. Please note that this configuration, especially the port number 9352 is a [[PKC]] specific specification.
<syntaxhighlight>
server {
    listen 80;
    location / {
        proxy_pass http://127.0.0.1:9352;
    }
}
</syntaxhighlight>
 
=Test Nginx and the Reverse Proxy=
Activate the directives by linking to /sites-enabled/ using the following command:
<syntaxhighlight>
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
</syntaxhighlight>
 
First, verify the syntax of all the above content is legitimate:
<syntaxhighlight>
sudo service nginx configtest
</syntaxhighlight>
 
Then, restart Nginx to kick it into action:
<syntaxhighlight>
sudo service nginx restart
</syntaxhighlight>
 
=Set up Let's Encrypt=
After setting up Nginx, one can consider setting up the free-of-charge Let's Encrypt certificate. The following instructions are modeled after this Medium article<ref>The Mightywomble, How to set up Nginx reverse proxy with let’s encrypt, Retried from:https://medium.com/@mightywomble/how-to-set-up-nginx-reverse-proxy-with-lets-encrypt-8ef3fd6b79e5</ref>:
 
=References=
<References/>

Latest revision as of 00:29, 8 May 2021