Last active
May 21, 2018 18:13
-
-
Save abhi11210646/46e22e149d5104c4564e4d0883da1108 to your computer and use it in GitHub Desktop.
nginx configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
server { | |
listen 80; | |
server_name example2.com www.example2.com xyz.example.com; | |
location / { | |
proxy_set_header HOST $host; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass http://localhost:3000 | |
} | |
} | |
https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1:- Install nginx. | |
sudo apt-get update | |
sudo apt-get install nginx | |
Step 2:- Create folder to store content which will be serverd by nginx. | |
sudo mkdir -p ~/example1.com/html // -p for creating multiple parents | |
sudo mkdir -p ~/example2.com/html | |
Step 3:- Cretae and update index.html files with dummy content. | |
nano ~/example1.com/html/index.html | |
nano ~/example2.com/html/index.html | |
Step 4:- Create server configuration file. | |
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example1.com | |
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example2.com | |
#It is advisable to create separate config file for each ste | |
Step 5:- Open config file. | |
sudo nano /etc/nginx/sites-available/example1.com | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
root ~/example1.com/html; | |
index index.html index.htm; | |
server_name example1.com www.example1.com; // domain names separated by space | |
location / { | |
try_files $uri $uri/ =404; // for angular2+ => try_files $uri $uri/ /index.html; | |
} | |
} | |
Step 6:- Enable config file's configuration(symbolic link) | |
sudo ln -s /etc/nginx/sites-available/example1.com /etc/nginx/sites-enabled/ | |
sudo ln -s /etc/nginx/sites-available/example2.com /etc/nginx/sites-enabled/ | |
#nginx uses server configuration from sites-enabled directory on startup | |
Step 7:- Disable default configuration | |
sudo rm /etc/nginx/sites-enabled/default | |
Step 8:- Restart nginx | |
## before restarting nginx run config test to be sure. | |
sudo nginx -t | |
sudo service nginx restart (or sudo systemctl restart nginx ) | |
Step 8:- setup hosts(optional) | |
sudo nano /etc/hosts | |
127.0.0.1 localhost | |
public.ip example1.com | |
public.ip example2.com | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment