Difference between revisions of "Set up Nginx as a Reverse Proxy"
Jump to navigation
Jump to search
BenKoo>Admin |
BenKoo>Admin |
||
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>: | 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>: | ||
=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> | 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> | <syntaxhighlight> | ||
Line 7: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Disable Default Virtual Host of Nginx= | |||
Then, try to unlink this existing link: | Then, try to unlink this existing link: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
Line 12: | Line 14: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Create the Reverse Proxy= | |||
Now go to the Nginx site-available directory | Now go to the Nginx site-available directory | ||
<syntaxhighlight> | <syntaxhighlight> | ||
Line 42: | Line 45: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Test Nginx and the Reverse Proxy= | |||
Activate the directives by linking to /sites-enabled/ using the following command: | Activate the directives by linking to /sites-enabled/ using the following command: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
Line 47: | Line 51: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
First, verify the syntax of all the above content is legitimate: | |||
<syntaxhighlight> | |||
service nginx configtest | |||
</syntaxhighlight> | |||
Then, restart Nginx to kick it into action: | |||
<syntaxhighlight> | |||
service nginx restart | |||
</syntaxhighlight> | |||
Revision as of 17:02, 24 April 2021
The first place to learn Nginx can be found in this book[1]:
Install Nginx
The following code can be copied and pasted to perform the task of installing Nginx on Ubuntu:[2]
sudo apt-get update
sudo apt-get install nginx -y
Disable Default Virtual Host of Nginx
Then, try to unlink this existing link:
sudo unlink /etc/nginx/sites-enabled/default
Create the Reverse Proxy
Now go to the Nginx site-available directory
cd /etc/nginx/sites-available
Use a text editor or copy a file with the following file name: reverse-proxy.conf
.
For example:
vi reverse-proxy.conf
Use a text editor or copy a file with the following file name: reverse-proxy.conf
.
For example, use the text editor vi, you can type the following command:
vi reverse-proxy.conf
In the file, type in the following content:
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:9352;
}
}
Test Nginx and the Reverse Proxy
Activate the directives by linking to /sites-enabled/ using the following command:
sudo ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
First, verify the syntax of all the above content is legitimate:
service nginx configtest
Then, restart Nginx to kick it into action:
service nginx restart
References
- ↑ 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
- ↑ Edward S., How to Set Up an Nginx Reverse Proxy, Retrieved from https://www.hostinger.com/tutorials/how-to-set-up-nginx-reverse-proxy/