forked from webmentordev/linux-bash-scripts-and-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nginx Domain Based API Serve.txt
40 lines (29 loc) · 1.13 KB
/
Nginx Domain Based API Serve.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
1 - Install Nginx
============================================================
$ sudo apt-get update
$ sudo apt-get install nginx
2 - Create Nginx Site name, it must match the domain. https://api.webmentor.dev
============================================================
$ sudo nano /etc/nginx/sites-available/api.webmentor.dev
3 - Write it in the file created in the command above
==============================================================
server {
listen 80;
server_name api.ahmerdev.online;
location / {
proxy_pass http://127.0.0.1:YOUR_API_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
4 - Create a Symbolic Link
==============================================================
$ sudo ln -s /etc/nginx/sites-available/api.webmentor.dev /etc/nginx/sites-enabled/
5 - Test if config is valid
==============================================================
$ sudo nginx -t
6 - Restart Nginx
==============================================================
$ sudo service nginx restart
Now visit the domain!