nginx反向代理其他端口

假设VPS IP为44.55.66.77,域名为mydomain.com,VPS系统为debian 9
VPS上make install安装了nginx,nginx version为1.15.1,nginx运行在80端口,一开始nginx.conf是这样,

...
http {
    server {
        listen 80;
        server_name mydomain.com;
        location / {
            root html;
            index index.html index.htm;
        }
    }
}
...

现在想通过nginx代理其他端口实现二级域名的效果,比如more.mydomain.com指向8090端口,配置是这样,

server {
    listen 80;
    server_name more.mydomain.com;
    location / {
        proxy_pass http://127.0.0.1:8090;
        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;
        root /usr/local/nginx/html;
        index index.html index.htm;
    }
}

nginx reload后访问more.mydomain.com提示找不到服务器 IP 地址
这种写法有问题吗?另外nginx添加ssl模块后如何代理?

#nginx.conf
server {
    listen 80;
    server_name mydomain.com;
    
    return 301 https://$host$request_uri;
}
阅读 3.8k
1 个回答

正规的server这样书写:
server {

    listen       8181;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

     root   E:/BsConfig/zhy_webclient;
    index  index.html;

    location /ma {
    proxy_pass http://localhost:9090;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

  
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题