全命令行安装宝塔服务器并通过域名访问

tips: 其实两年前写过,但是...数据全丢失了

登录服务器

ssh xxx@ip
# 这一步都不会就不用往下看了

下载BT

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

命令行安装Nginx

# 你的默认目录也是 /www
cd /www/server/panel/install/ && chmod +x install_soft.sh
./install_soft.sh nginx install 1.21

此处可能会出现错误,看此处

如果你执行出错,有可能是没有lib.sh,下载后放到/www/server/panel/install/

或者直接使用nginx.sh脚本

# 确保按照 gd
yum install -y gd-devel.x86_64 
wget http://download.bt.cn/install/1/nginx.sh && bash nginx.sh install 1.21

设置域名访问面板

  • 修改默认nginx.conf (作用是可通过socket链接)
 vi /www/server/nginx/conf/nginx.conf
 # 大概在第17行找到 #include luawaf.conf; 在后方添加
 map $http_upgrade $connection_upgrade {
            default upgrade;
            '' close;
         }

nginx.conf配置后

  • 添加 域名配置文件 vi /www/server/panel/vhost/nginx/host.conf
server
# 注意修改自己需要的域名
{
    listen 80;
    server_name inner.gtdstudio.com; # 在此修改
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/innerhost;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-00.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    #REWRITE-END
    location /
    {
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        
        add_header X-Cache $upstream_cache_status;
        
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;   # 升级协议头
        proxy_set_header Connection "upgrade";
        #Set Nginx Cache
        add_header Cache-Control no-cache;
        expires 12h;
    }
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }
    
    access_log  /www/wwwlogs/innerhost.log;
    error_log  /www/wwwlogs/innerhost.error.log;
}
  • 重启nginx 可以通过域名访问了
service nginx reload