linux环境部署前端我的项目

  • 装置node

    举荐装置nvm来装置和治理node版本:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bashwget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash#通过nvm装置nodejsnvm install node

    留神:

    在终端间接执行nvm没问题,执行shell脚本中的nvm提醒bash: nvm: command not found…
    起因:nvm是一个脚本不是指令,所以shell脚本中执行nvm会提醒bash: nvm: command not found…
    解决:只需在执行nvm前加一行指令即可解决问题:source ~/.nvm/nvm.sh
    留神: ~/.nvm是nvm的装置门路,须要写nvm的理论装置门路,能够用find / -name “.nvm” 来查找nvm的装置目录

  • 装置nginx

    先创立/etc/yum.repos.d/nginx.repo文件内容如下:

    [nginx-stable]name=nginx stable repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true[nginx-mainline]name=nginx mainline repobaseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/gpgcheck=1enabled=0gpgkey=https://nginx.org/keys/nginx_signing.keymodule_hotfixes=true

    再运行:

    sudo yum install nginx
  • 运行nginx

    whereis nginx

    装置后网站的配置文件会在 /etc/nginx/conf.d/目录下,新增网站时只有在此目录下新增一份配置文件,或者间接利用/etc/nginx/nginx.conf文件,其内容如下:

    # For more information on configuration, see:#   * Official English Documentation: http://nginx.org/en/docs/#   * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {    worker_connections 1024;}http {    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  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 4096;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    # Load modular configuration files from the /etc/nginx/conf.d directory.    # See http://nginx.org/en/docs/ngx_core_module.html#include    # for more information.    include /etc/nginx/conf.d/*.conf;    server {        listen       80;        listen       [::]:80;        server_name  _;        root         /usr/share/nginx/html;        # Load configuration files for the default server block.        include /etc/nginx/default.d/*.conf;        error_page 404 /404.html;        location = /404.html {        }        error_page 500 502 503 504 /50x.html;        location = /50x.html {        }    }# Settings for a TLS enabled server.##    server {#        listen       443 ssl http2;#        listen       [::]:443 ssl http2;#        server_name  _;#        root         /usr/share/nginx/html;##        ssl_certificate "/etc/pki/nginx/server.crt";#        ssl_certificate_key "/etc/pki/nginx/private/server.key";#        ssl_session_cache shared:SSL:1m;#        ssl_session_timeout  10m;#        ssl_ciphers HIGH:!aNULL:!MD5;#        ssl_prefer_server_ciphers on;##        # Load configuration files for the default server block.#        include /etc/nginx/default.d/*.conf;##        error_page 404 /404.html;#            location = /40x.html {#        }##        error_page 500 502 503 504 /50x.html;#            location = /50x.html {#        }#    }}

    能够看到 root /usr/share/nginx/html;咱们此时只须要将前端我的项目打包,将dist目录下的内容复制到 /usr/share/nginx/html目录下,

    而后从新利用下配置文件就能够了。这里介绍下nginx罕用的命令:

    #测试配置文件是否失常nginx -t#nginx版本nginx -v#从新利用配置文件nginx -s reload#进行 nginx 命令:nginx -s stop#启动 nginx 命令:nginx或者/usr/sbin/nginx -c /etc/nginx/nginx.conf

    查看linux 凋谢的所有端口netstat -ntpl

    查看nginx 的状态 ps -ef | grep nginx 呈现master 则启动胜利

本文由mdnice多平台公布