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    mqtt.kfpt.cn;
            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:18083;
            }
}
 
server{
        listen    80;
        server_name    nginx.kfpt.cn;
            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:18083;
            }
}


5、重启nginx

    service nginx restart

6、访问测试

    依次访问上面域名:mqtt.kfpt.cn、mqtt.kfpt.cn

7、域名备案

    登录阿里云,点击右上角【备案】,按步骤完成备案即可

ps:自动启动Nginx 

设置nginx 自动开机启动 :chkconfig --level 235 nginx on

你可能感兴趣的:(Linux)