假设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;
}
正规的server这样书写:
server {