安装还是比较简单的,就不详细说了,一般都是用系统自带的包管理工具安装
centos 安装:
yum install nginx
ubuntu 安装:
apt install nginx
更改 nginx 配置文件 / etc/nginx/conf.d/default.conf
好习惯先备份一下 default.conf
- cd /etc/nginx/conf.d
- cp default.conf default.conf.bak
- vi default.conf
添加你需要转发的域名,举例如下:
- server {
- listen 80;
- server_name domain1.com;
- location / {
- proxy_pass http: //localhost:10001;
- }
- }
- server {
- listen 80;
- server_name domain2.com;
- location / {
- proxy_pass http: //localhost:10002;
- }
- }
这个实现的效果就是 http://domain1.com 转发到
上,http://domain2.com 转发到
- http://localhost:10001
上
- http://localhost:10002
最后,重启 nginx
- service nginx restart
来源: http://www.jianshu.com/p/7d55931001c4