nginx做二级域名转发显示端口号!!

牛海朋 2017-02-03 04:40:42
最近申请了域名 abc.com,ip 192.168.1.17,因为我只有一台服务器,上面打算部署多个应用,其中一个博客应用部署在8081端口,gitlab部署在8082端口,已经在dns解析上将 blog.abc.com和gitlab.abc.com都配置为192.168.1.17,通过浏览器访问时,域名后面加上了端口号,例如访问blog.abc.com浏览器地址变为blog.abc.com:8081,请教大家怎么可以不显示端口号!下面是我的nginx配置。

nginx.conf

user  nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}



/etc/nginx/conf.d/blog.conf

upstream blog.abc.com {
server 192.168.1.17:8081 weight=1 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
server_name blog.abc.com;
server_name_in_redirect off;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://blog.abc.com/;
}
}


/etc/nginx/conf.d/gitlab.conf

upstream gitlab.abc.com {
server 192.168.1.17:8082 weight=1 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
server_name gitlab.abc.com;
server_name_in_redirect off;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://gitlab.abc.com/;
}
}
...全文
738 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
牛海朋 2017-02-04
引用 3 楼 baidu_19473529 的回复:
引用 2 楼 niu323 的回复:
[quote=引用 1 楼 baidu_19473529 的回复:] proxy_set_header Host $host:$server_port; 没加$server_port就老是到下级请求出现真实端口号。
然后怎么解决啊
server { listen 80; server_name localhost; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://127.0.0.1:8080/; } } [/quote]试了,,,不好使!!!!!!!!!!!!
  • 打赏
  • 举报
回复
引用 2 楼 niu323 的回复:
引用 1 楼 baidu_19473529 的回复:
proxy_set_header Host $host:$server_port; 没加$server_port就老是到下级请求出现真实端口号。
然后怎么解决啊
server { listen 80; server_name localhost; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://127.0.0.1:8080/; } }
  • 打赏
  • 举报
回复
牛海朋 2017-02-03
引用 1 楼 baidu_19473529 的回复:
proxy_set_header Host $host:$server_port; 没加$server_port就老是到下级请求出现真实端口号。
然后怎么解决啊
  • 打赏
  • 举报
回复
proxy_set_header Host $host:$server_port; 没加$server_port就老是到下级请求出现真实端口号。
  • 打赏
  • 举报
回复
相关推荐
发帖
Apache

2.4w+

社区成员

Web 开发 Apache
社区管理员
  • Apache
加入社区
帖子事件
创建了帖子
2017-02-03 04:40
社区公告
暂无公告