对于Nginx,一个IP上配置多个站点还是很常见的。尤其是在开发环境上,更是如此
配置nginx
修改ngnix配置支持include配置文件
凡事先备份,小心驶得万年船啊!
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
mkdir /etc/nginx/sites-avaiable
编辑 /etc/nginx/nginx.conf ,添加对多站点配置的支持
在 http { } 块的末尾加上下面两行:(即在在 } 的前面添加)
include /etc/nginx/sites-avaiable/*.conf;
server_names_hash_bucket_size 64;
建立站点配置,以tensweets.com为例:
cp /etc/nginx/conf.d/default.conf /etc/nginx/sites-available/tensweets.com.conf
eg:tensweets.com.conf的配置如下,将对tensweets.com的访问转发到本机的8008端口
server {
listen 80;
server_name tensweets.com www.tensweets.com;
location / {
proxy_pass http://localhost:8008;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
重启Nginx服务
systemctl restart nginx
或者也可以 service nginx restart
如果遇到错误: nginx -t -c /etc/nginx/nginx.conf
检查下配置文件是否正确
最后访问你的浏览器,看看网站是否正常!