阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
1、安装nginx
yum -y install nginx
2、启动nginx
service nginx start
3、访问(nginx默认是80端口)
curl 127.0.0.1
4、域名子绑定
编辑文件/etc/nginx/conf.d/default.conf,在底部加入下面代码,完成前几章所述4个端口的子域名绑定
server{
listen 80;
server_name tomcat.bingzhenmifan.com;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:14802;
}
} server{
listen 80;
server_name jetty.bingzhenmifan.com;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:14808;
}
} server{
listen 80;
server_name resin8080.bingzhenmifan.com;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
} server{
listen 80;
server_name resin14805.bingzhenmifan.com;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:14805;
}
}
5、重启nginx
service nginx restart
6、访问测试
依次访问上面4个域名:tomcat.bingzhenmifan.com、jetty.bingzhenmifan.com、resin8080.bingzhenmifan.com、resin14805.bingzhenmifan.com
注意:如果域名没有备案的话,在本地是打不开网站的,可以在云服务器上使用curl命令访问
7、域名备案
登录阿里云,点击右上角【备案】,按步骤完成备案即可