前端小白爬坑记(四)操作系统Linux(CentOS 8.0 64bit) 网站部署的环境配置(纯静态页面的环境配置,不带有后台。)

938 阅读4分钟

在没有接触服务器之前,一直以为服务器是个高大上的东西。

刚开始作为一个纯小白,不怕诸位笑话,就连接windows服务器都不会,还没有琢磨明白windows服务器,公司已经开始使用Linux服务器,所幸身处资源共享的年代,很多好的学习资料对我的帮助很大。

这里感谢各位大佬的技术分享。

由于很久没有配置服务器环境,刚好遇到腾讯云服务器有活动,便入手一台练练手,进行Linux服务器配置,这里做一个记录。

首先,花巨资70元大钞购买的轻量级服务器,必须安排上炫下配置,放两三个网站页面妥妥没问题,要用自身稳稳的土豪气质闪亮诸位的大眼。

2022-02-18_105418.png

一.修改服务器密码

1.找到服务器的实例 -> 选择更多

2022-02-18_103044.png

2.选择管理

2022-02-18_103105.png

3.选择重置密码

2022-02-18_103156.png

4.进行密码重置

2022-02-18_103208.png

二.连接服务器

1.进入Xshell 7

文件 -> 新建会话

image.png

名称:根据自身需求写。

主机:服务器的IP

然后选择连接

image.png

输入登录用户

image.png

输入登录密码,然后确定。

image.png

2.连接成功之后的提示

image.png

三.静态页面的Nginx环境配置

1.手动配置Nginx

1.配置Nginx代理

进入nginx网站: nginx.org/en/download…

点击中间的版本就是Linux

image.png

下载完成之后,使用Xftp进行上传

image.png

这里我先找到Home, 使用 mkdir 创建目录,用来存放压缩文件。

image.png

上传成功之后,ls 查看下文件

image.png

开始解压文件:

执行Linux命令: tar -zxvf nginx-1.20.2.tar.gz

安装成功之后进入目录查看 image.png

配置configure: ./configure 自动配置

image.png

执行的时候报错:

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option.

image.png

安装pcre-devel解决问题

执行命令:yum -y install pcre-devel

image.png

安装好pcre-devel之后,再次 ./configure 成功了

image.png

如果报错是:make: *** No rule to make target build', needed by default'. Stop.

  1. 安装下面配置 yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

  2. 验证

./configure

configure成功之后,make下。(编译 make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件)

image.png

稳妥一步执行下安装 make install 

Nginx安装成功后,修改端口号和启动

执行:whereis nginx 找到nginx的位置

image.png

cd /usr/local/nginx

执行 ll 查看

image.png

端口号的配置再conf中

cd conf/ 进入conf文件中 找到nginx.conf配置文件

使用cat nginx.conf 查看文件

这里我将文件传输到桌面查看。

image.png

配置中默认是80端口,我改成8081.

image.png

image.png

改好后替换原来的文件,同时再腾讯云的防护墙开放端口,阿里云在安全组开放端口

image.png

开始启动nginx

cd sbin

image.png

执行 nginx

./nginx

image.png

IP:8081 端口号,成功打开就行了

image.png

可以开始正式部署官网了:

开始为了测试,所以将80改为8081,现在改回:80

    location / {
        root   /home/guanWang/fxgyPC;
        index  index.html;
    }
    

/home/guanWang/fxgyPC 是项目所在的位置(一般新建一个文件夹存放项目)

image.png

修改完之后重新替换nginx.conf文件。

先关闭已开启的nginx:

查看运行的进程 ps -ef|grep nginx

关闭进程:kill -9 53614

然后重新启动 ./nginx

浏览器打开网站,这里的域名已经解析到服务器上了,所以直接打开就行。

注:不要打开这个网址,部署成功之后就删除解析,看不到页面。

image.png

如果要部署多个二级域名

server_name 对应域名

location / { root /home/guanWang/web/fxgyPC; index index.html; }

    root  对应项目地址

server {
    listen       80;
    server_name  ap.lemonforever.top;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /home/guanWang/web/fxgyPC;
        index  index.html;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

四.宝塔部署网站

宝塔网址:www.bt.cn/download/li…

选择Linux面板

image.png

点击立即安装会出现对应的命令

image.png

我这里选择: yum install -y wget && wget -O install.sh download.bt.cn/install/ins… && sh install.sh

成功之后会给你访问地址,账号,密码。

image.png

登录之前一定要在腾讯云或阿里云开启宝塔的默认端口号:8888

image.png

进入之后需要简单的注册下,就可以使用了

image.png

找到软件商店,选择需要安装的东西

image.png

找到apache,进行安装

选择需要的版本和安装方式。

image.png

进入安装

image.png

安装成功

image.png

找到网站 添加站点

image.png

输入域名信息

image.png

image.png

image.png

将代码内容进行上传

image.png

打开成功

image.png

五.静态页面的tomcat环境配置

进入tomcat官网:tomcat.apache.org/

image.png

选择对应版本进入,下载对应系统的tomcat

image.png

我这里下载的是8.5版本 image.png

通过Xftp将包输入到目录下

image.png

解压 apache-tomcat-9.0.8.tar.gz

执行命令:tar -zxvf apache-tomcat-9.0.8.tar.gz

进入解压好的tomcat文件中,进行配置。

image.png

找到conf里的server文件 image.png

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
           
prot改为80

image.png

修改域名配置

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>
  

将name="localhost" 换成 name="www.lemonforever.top"

加入

docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/ce" 是项目所在的地址

image.png

添加二级域名配置

 <!--二级域名ap.lemonforever.top-->
<Host name="ap.lemonforever.top"  appBase="webapps"  
        unpackWARs="true" autoDeploy="true"  
        xmlValidation="false" xmlNamespaceAware="false"> 
   <Context path="" docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/fxgyPC" debug="0" reloadable="true" />
 </Host>
 
 

docBase="/home/GuanWang/apache-tomcat-8.5.63/webapps/fxgyPC"是项目所在的地址

项目放在apache-tomcat-8.5.63 中的webapps 文件中

image.png

image.png

image.png

修改完替换原来的配置文件

现在开启tomcat,试试网站是否可以打开

进入bin文件下

image.png

./startup.sh

image.png

报错了: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program

没有安装JDK,找不到环境变量,所以无法启动.

这里说明下,有人跟我说运行tomcat,不需要jdk。所以这里就顺便实践下,事实说明要装jdk。

下面开始安装jdk

传入jdk-8u271-linux-x64.rpm

检测JDK版本信息 rpm -ga|grep jdk

有就卸载,重新装。

卸载命令: rpm -e --nodeps jdk_版本号

新的服务器没有我这里就直接安装了

rpm -ivh jdk-8u271-linux-x64.rpm

image.png

安装完毕之后检测是否成功

java -version

image.png

安装好之后进行环境配置

进入etc目录 找到profile文件。

image.png

我这里的习惯还是导出来,在编译器中修改,方便。

image.png

加入以下配置

export JAVA_HOME=/usr/local/jdk/jdk1.8.0_181 (注意:jdk1.8.0_271-amd64安装的目录在 /usr/java) export PATH=JAVAHOME/bin:JAVA_HOME/bin:PATH

image.png

重新加载配置文件

命令 source /etc/profile

image.png

java -version

如果出现版本号证明环境配置成功

下面就是开启tomcat

./startup.sh

image.png

开启成功,打开页面瞅瞅

image.png

再次提醒,成功之后就删除配置了,网站打不开。

有不对的地方欢迎大佬们指正,后面会记录下有后端的环境配置。