手动部署LNMP环境(CentOS 7)

连接到服务器

ssh root@[服务器IP地址],然后输入服务器密码

退出服务器

  1. logout

配置Web服务器(nginx)

  1. 运行以下命令备份Nginx配置文件。

    1. cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
  2. 运行以下命令打开Nginx配置文件。

    1. vim /etc/nginx/nginx.conf
  3. 修改nginx权限

user nginx; => user root;

  1. Server大括号内,添加下列配置信息

前端工程放到www文件夹下

  1. location / {
  2. root /root/www/;
  3. index index.html index.htm;
  4. try_files $uri /index.html;
  5. }
  6. location /api {
  7. proxy_pass http://localhost:8000;
  8. proxy_set_header Host $host;
  9. }

如果使用BrowserRouter,还需要设置try_files

  1. location / {
  2. root /root/www/;
  3. index index.html index.htm;
  4. try_files $uri /index.html;
  5. }
  6. location /api {
  7. proxy_pass http://localhost:8000;
  8. proxy_set_header Host $host;
  9. }
  1. 运行以下命令启动Nginx服务。

    1. systemctl start nginx
  2. 运行以下命令设置Nginx服务开机自启动。

    1. systemctl enable nginx

检查Web配置:nginx -t
查看Web服务:ps -ef | grep nginx
启动Web服务:nginx
停止Web服务:nginx -s stop
重启Web服务:nginx -s reload

补充:如果删除文件的时候发生文件太大导致错误发生,把以下内容加入到配置文件中
#vim /etc/nginx/nginx.conf

  1. client_max_body_size 20M

设置到http{}内,控制全局nginx所有请求报文大小
设置到server{}内,控制该server的所有请求报文大小
设置到location{}内,控制满足该路由规则的请求报文大小

!!强烈建议:开启gzip压缩,可以极大的缩短页面加载时间

  1. server {
  2. listen 80 default_server;
  3. listen [::]:80 default_server;
  4. server_name _;
  5. root /usr/share/nginx/html;
  6. # Load configuration files for the default server block.
  7. include /etc/nginx/default.d/*.conf;
  8. location / {
  9. root /root/www/;
  10. index index.html index.htm;
  11. try_files $uri /index.html;
  12. }
  13. location /api {
  14. proxy_pass http://localhost:8000;
  15. proxy_set_header Host $host;
  16. }
  17. error_page 404 /404.html;
  18. location = /40x.html {
  19. }
  20. error_page 500 502 503 504 /50x.html;
  21. location = /50x.html {
  22. }
  23. #on为启用,off为关闭
  24. gzip on;
  25. #设置允许压缩的页面最小字节数,页面字节数从header头中的Content-Length中进行获取。默认值是0,不管页面多大都压缩。建议设置成大于1k的字节数,小于1k可能会越压越大。
  26. gzip_min_length 1k;
  27. #获取多少内存用于缓存压缩结果,‘4 16k’表示以16k*4为单位获得
  28. gzip_buffers 4 16k;
  29. #gzip压缩比(1~9),越小压缩效果越差,但是越大处理越慢,所以一般取中间值
  30. gzip_comp_level 5;
  31. #对特定的MIME类型生效,其中'text/html’被系统强制启用
  32. #gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
  33. gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  34. #gzip_http_version 1.0;
  35. }

上传文件到服务器

  • 使用scp命令
  • scp -r local_dir user@ip:remote_dir
  1. cd [前端工程目录]
  2. scp -r ./* root@[服务器IP地址]:/root/www

./* 表示当前目录下的所有文件
所以,以上命令的意思就是:把当前文件夹里的所有文件,上传到服务器的www文件夹下
上传完文件之后,直接在浏览器中输入服务器地址,就能看到网站了

终端中文显示

  1. 查看系统是否安装中文包

    如果出现以下结果,说明已经安装中文包

    1. [root@chenyisong logs]# locale -a | grep "zh_CN"
    2. zh_CN
    3. zh_CN.gb18030
    4. zh_CN.gb2312
    5. zh_CN.gbk
    6. zh_CN.utf8
  2. 修改配置文件:vim /etc/locale.conf

    1. LANG="zh_CN.UTF-8"  //改成自己需要的编码格式
  3. 重启服务器

然后做一下操作启动相关进程
cd redis-5.0.5 => make => src/redis-server
cd server => npm run prd

JDK环境搭建及项目部署

  • Linux/Unix操作系统上JDK环境的配置
  • Linux/Unix操作系统上web运行环境的配置
  • Linux/Unix操作系统上java项目的部署发布