共计 2983 个字符,预计需要花费 8 分钟才能阅读完成。
linux 环境部署前端我的项目
-
装置 node
举荐装置 nvm 来装置和治理 node 版本:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash #通过 nvm 装置 nodejs nvm 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 repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_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 多平台公布
正文完