鍍金池/ 問答/Linux/ nginx反向代理其他端口

nginx反向代理其他端口

假設(shè)VPS IP為44.55.66.77,域名為mydomain.com,VPS系統(tǒng)為debian 9
VPS上make install安裝了nginx,nginx version為1.15.1,nginx運(yùn)行在80端口,一開始nginx.conf是這樣,

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

現(xiàn)在想通過nginx代理其他端口實(shí)現(xiàn)二級(jí)域名的效果,比如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提示找不到服務(wù)器 IP 地址。
這種寫法有問題嗎?另外nginx添加ssl模塊后如何代理?

#nginx.conf
server {
    listen 80;
    server_name mydomain.com;
    
    return 301 https://$host$request_uri;
}
回答
編輯回答
卟乖

正規(guī)的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;
    }

  
}
2018年2月18日 14:43