银河麒麟系统+飞腾CPU 部署nginx(运行vue项目)

目录

  • 部署nginx
    • 前言
    • 正文
    • 附言

部署nginx

前言

写在前面:
由于我的系统root用户无法登录,所以下面的命令我都用sudo执行的,如果你的系统可以登录root,记得一定要用root用户进行操作哦,还要记得把下面命令前面的sudo删掉;(不用root用户真的会碰到好多问题)

切换root用户命令:su root

之后输入密码就好;
我部署nginx主要为了运行基于vue框架的前端项目,这里只是做个记录,希望能帮到有需要的你们;
注意:如复制命令,请先注意一下我遇到的问题,因为我是边写边运行的,有些问题可能你们遇不到哦,因为我不是用root用户操作的;

正文

输入命令下载组件(在自己喜欢的目录,我用的目录是/usr/local/nginx):
注:这里最好别跟我一样,因为忘记了nginx安装正好是安装在这个目录下的,所以把这些安装包安到这里后面一看会很乱(不影响使用,这里我以后也会改的,这次弄的比较急,抱歉哦大家)

--下载组件
sudo wget http://nginx.org/download/nginx-1.10.2.tar.gz
sudo wget http://www.openssl.org/source/openssl-fips-2.0.16.tar.gz
sudo wget http://zlib.net/zlib-1.2.11.tar.gz
sudo wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz

--解压组件
sudo tar -zxvf nginx-1.10.2.tar.gz 
sudo tar -zxvf openssl-fips-2.0.10.tar.gz
sudo tar -zxvf pcre-8.40.tar.gz
sudo tar -zxvf zlib-1.2.11.tar.gz

--安装组件
cd openssl-fips-2.0.10/
sudo ./config && make && make install

cd ../pcre-8.40/
//sudo ./configure && make && make install  我用这段命令执行后报如下错误
//Makefile:2970: recipe for target 'install' failed
//make: *** [install] Error 2
sudo apt install libpcre3-dev   //这里是由于我用上面的命令报错,改用这个命令后安装成功
pcre-config --version    //之后用如下命令检查是否安装成功

cd ../nginx-1.10.2/
//
//sudo ./configure && make && make install 我用这段命令报如下错误:
/*致命错误:can't create objs/src/core/nginx.o: 权限不够
objs/Makefile:353: recipe for target 'objs/src/core/nginx.o' failed
make[1]: *** [objs/src/core/nginx.o] Error 2
make[1]: Leaving directory '/usr/local/nginx/nginx-1.10.2'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2*/
//之后我一行一行执行,提示安装成功
sudo ./configure;
sudo make;
sudo make install;

//但是启动nginx的时候又报如下错误
/*
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2021/06/04 16:39:02 [emerg] 17309#0: mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)
*/
//经过检查原因是我用的不是root用户,对这个文件夹没有权限,所以我又给这个文件夹附了权限,命令如下
sudo chown -R kylin nginx/     //如果你想附给某个用户,把kylin换成对应用户名就好
//之后启动nginx
cd /usr/local/nginx/sbin;
sudo ./nginx;
//停止nginx
/usr/local/nginx/sbin/nginx -s stop

nginx基本命令:

/usr/local/nginx/sbin/nginx#启动
/usr/local/nginx/sbin/nginx -s stop(quit、reload)#停止/重启
/usr/local/nginx/sbin/nginx -h#命令帮助
vi /usr/local/nginx/conf/nginx.conf#配置文件

修改nginx配置文件;

vi /usr/local/nginx/conf/nginx.conf

我的配置文件内容如下(我的vue项目路径为:/data/dist):


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8081;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        
        # index index.html index.htm;
 
        location / {
            try_files $uri $uri/ /index.html;
	    root /data/dist;
	    index  index.html index.htm;
        }

        #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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

之后启动nginx;
运行后端程序(java -jar **.jar);
打开浏览器输入url(localhost:8081/#/main);
页面显示正常,部署成功!!!!

附言

后端框架:springboot
前端框架:vue

全为最基础的框架,只是链接达梦数据库,在页面上显示出数据库内信息;
想查看框架搭建内容可以点下面链接进入哦:

纯国产环境JAVA程序(Springboot + Mybatis + 达梦数据库)搭建

纯国产环境(银河麒麟 + 飞腾)JAVA程序(Springboot + Mybatis + 达梦数据库)部署

你可能感兴趣的:(麒麟系统,nginx,linux,java,数据库)