我们在阿里云的服务器上启动两个http服务,分别监听的是8888端口和8080端口,我们想通过两个不同的域名来访问到这两个web服务,(假设这两个域名分别是:helloword.com和admin.helloword.com)
nginx配置:
server {
listen 80;
server_name helloword.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8888;
}
}
server {
listen 80;
server_name admin.helloword.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8080;
}
}
如果我们想把/usr/share/nginx/admin
这个静态页绑定一个域名:
server {
listen 80;
server_name static.helloword.com;
location / {
root /usr/share/nginx/admin;
index index.html index.htm;
}
}