nginx+tomcat绑定域名配置

1,配置nginx,首先去官网下载nginx,地址为:http://nginx.org/en/download.html,可以到这里去下载最新版本

2,找到nginx/conf/nginx.conf,修改配置:

upstream web{   #第三步,设置本地计算机tomcat服务器具体的 ip+端口号
    server localhost:8080;
}
server {
    listen       80;
    server_name  demo.xxx.com;   #第一步,我们在网页端输入的网址
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {  #第二步,我们的"/"符号表示拦截所有请求
        proxy_pass http://local_tomcat#第二步中,设置 http:// +映射访问的网址
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

 

3,如果有涉及xxx.com ,  可以设置用户输入: xxx.com自动转发到www.xxx.com
server {
    server_name xxx.com;
    rewrite ^(.*) http://www.xxx.com$1 permanent;
}

posted @ 2018-01-03 18:03  chenhuan  阅读(3807)  评论(0编辑  收藏  举报