nginx实现同一端口url转发到多个端口和服务器备份(公司附件无法上传)

第一步:上传文件服务器

1、 在服务器根目录创建nginx文件夹,上传 nginx-1.3.15.tar.gz 和 nginx.sh到

nginx文件夹下



2、 解压 nginx-1.3.15.tar.gz

第二步:安装文件

1、 进入/nginx/nginx-1.3.15目录下

2、 分别执行下列命令安装软件:(安装默认目录/usr/local/nginx)

./configure

make

make install

第三步:修改配置文件

1、 进入/usr/local/nginx/conf目录修改nginx.conf文件

2、 修改内容说明:

红色部分为添加的代码

“80”为 10.200.130.71服务器端口号

通过访问服务器http:// 100.200.130.79:80/test可以调整到http:// 100.200.130.79:8088/test



server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
}

location /test{
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http:// 100.200.130.79:8088/test(转发服务器url);
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

第四步:设置nginx服务

1、 将/nginx 下复制nginx.sh到/etc/init.d/nginx下

(执行 cp nginx.sh /etc/init.d/nginx)

2、 将nginx添加为可执行服务(执行chmod u+x /etc/init.d/nginx

查 看nginx是否添加成功执行 ll /etc/init.d/nginx)

3、 添加到启动服务器时nginx服务默认启动

(执行chkconfig --add nginx

chkconfig nginx on
chkconfig --list



4、启动nginx服务。

(启停nginx服务命令:

service nginx start

service nginx stop)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值