ubuntu中使用nginx把本地80端口转到其他端口

来源:互联网 发布:java堆栈图解 编辑:程序博客网 时间:2024/06/10 23:16

配置转发

nginx的默认安装路径在/usr/local/nginx下.
nginx的默认配置在/etc/nginx下.

把80端口指向8080端口, 方法如下:

修改nginx.conf

注释掉改行:

 #nginx.conf 中 http 段最后会有以下这两句.    #这样你就可以把已经配置好的各种 server conf 放在 sites-available 里,    #如果想启用的时候只要复制或者软连接到上面两个文件夹里,想关掉或者更改配置的时候也比较方便.    #    #而默认情况下sites-enabled目录下会放一个sites-available/default的软链接,    #在sites-available/default已经对localhost进行设置,     #导致无论你怎么修改nginx.conf对本地端口进行配置都不会生效. 一直报404错误.    #所以此处要把sites-enabled注掉. 或者把该软链接换掉.    #    include /etc/nginx/conf.d/*.conf;    #include /etc/nginx/sites-enabled/*; 

在http配置项中增加如下内容:

server {        listen 80;        server_name localhost;        location / {            proxy_pass http://localhost:8080;            proxy_redirect off;            proxy_set_header Host $host;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            proxy_set_header X-Real-IP $remote_addr;        }    }

重启NGINX生效。

0 0
原创粉丝点击