博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何用nginx在本地把9000端口转发到80端口上
阅读量:7022 次
发布时间:2019-06-28

本文共 866 字,大约阅读时间需要 2 分钟。

hot3.png

起因看到一个用java写的轻博客,于是就兴致冲冲的试用一下。由于是lnmp的环境,Nginx占用了80端口,新博客只能用其他的端口,这里选择了9000端口,本地测试没问题。总不能访问了域名然后在加上端口号吧。于是就想着用Nginx来反向代理本地的9000端口

如何用nginx在本地把9000端口转发到80端口上如何用nginx在本地把9000端口转发到80端口上

配置

新建一个配置文件

vim www.ti3.cc.conf

输入以下配置

listen 80;server_name localhost www.ti3.cc ti3.cc;location / {proxy_pass http://localhost:9000;proxy_redirect default;}}

wq 保存,重载Nginx

service nginx reload

结果改进版:

创建一个配置文件(以www.ti3.cc为例)

vim www.ti3.cc.conf

输入一下配置

server{listen 80;server_name www.ti3.cc;location /{proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:9000;}location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?${proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;proxy_pass http://localhost:9000;}access_log /www/wwwlogs/ti3.cc.log;}

wq保存

转载于:https://my.oschina.net/u/3585265/blog/3008350

你可能感兴趣的文章
1029.在线视频—开源网管Cacti系列讲座(四)多种数据采集方式
查看>>
如何设置主机的ssh的端口号
查看>>
DDOS防御总结
查看>>
rem windows服务器时间同步
查看>>
Android 获取手机IMEI方法
查看>>
Linux应用开发自学之路
查看>>
windows8小技巧之快捷键
查看>>
python(运算符)
查看>>
tomcat的安装
查看>>
PHP教程:详解PHP归并排序的实现
查看>>
云计算应用场景有哪些?
查看>>
防止SQL注入解决方案
查看>>
python新手入门常犯的错误
查看>>
javascript之this指向
查看>>
FTP实时更新上传脚本
查看>>
awk中多个分隔符^识别办法
查看>>
Centos7 初始化MySQL5.7数据库
查看>>
从零开始的linux 第十八章
查看>>
c#获取逻辑硬盘信息
查看>>
vSphere虚拟化之vClient安装虚拟机
查看>>