vue前端分离打包部署

vue前端分离打包部署

项目配置

  1. congig/index.js
    1. 修改 assetsPublicPath: ‘./’
  2. 运行npm run build 进行打包

centos nginx配置

  1. 下载安装包

    • cd /usr/local/software
    • wget http://nginx.org/download/nginx-1.6.2.tar.gz
  2. 下载依赖库

    • yum install gcc-c++
    • yum install pcre
    • yum install pcre-devel
    • yum install zlib
    • yum install zlib-devel
    • yum install -y openssl
    • yum install -y openssl-devel
  3. 解压安装

    • tar -zxvf nginx-1.6.2.tar.gz -C /usr/local
      • (local这个目录类似于Windows的program目录,所以一些软件可以都安装在这里)
  4. 配置configure

    • cd /usr/local/nginx-1.6.2
    • ./configure --prefix=/usr/local/nginx
  5. 编译安装

    • make
    • make install
  6. 启动nginx

    • /usr/local/nginx/sbin/nginx
    • /usr/local/nginx/sbin/nginx -s stop
      • 此方式停止步骤是待nginx进程处理任务完毕进行停止。
    • /usr/local/nginx/sbin/nginx -s quit
      • 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
    • /usr/local/nginx/sbin/nginx -s reload
  7. 查看nginx进程

    • ps aux | grep nginx
  8. nginx开机自启动设置

    • rc.local增加启动代码
      • vi /etc/rc.local
      • /usr/local/nginx/sbin/nginx
    • 更改权限
      • chmod 755 rc.local

前端部署Nginx配置

  1. 把打包好的文件放在centos系统下的nginx文件目前里面
    1. /usr/local/nginx
  2. 进入/usr/local/nginx/conf文件夹 配置nginx.conf
  3. vim nginx.conf

#user  root;
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压缩服务
	gzip  on;
    gzip_proxied any;
    gzip_min_length  1024;
    gzip_buffers    4 8k;
    gzip_comp_level 3;
    gzip_types      text/plain text/css application/x-javascript application/javascript application/xml application/json;

    server {
        listen       8088;
		# 监听8088端口
        server_name  localhost;
		# 配置基于名称虚拟主机
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   dist;
			autoindex on;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
			autoindex_exact_size off;
			autoindex_localtime on;
        }
		location @router {
            rewrite ^.*$ /index.html last;
        }

		# admin 服务API配置
		location /admin {
            rewrite ^.+apis/?(.*)$ /$1 break;
			proxy_pass http://192.168.16.116:9999/admin;
        }
        # 禁止直接访问static文件目录
		location =/static/ {
		  deny all;
		}
		
		# 禁止直接访问static/js文件目录
		location =/static/js/ {
		  deny all;
		}
		
		# 禁止直接访问static/fonts文件目录
		location =/static/fonts/ {
		  deny all;
		}
		
		# 禁止直接访问static/css文件目录
		location =/static/css/ {
		  deny all;
		}
        # 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;
    #    }
    #}

}
  1. 重启nginx

部署完毕可能出现的问题

  1. 外部访问不了,但是虚拟机能访问(无法打开到主机的连接。 在端口 23: 连接失败)
    • 造成原因:firewall防火墙原因
      • firewall-cmd --zone=public --list-all
        • 查看ports 端口
      • firewall-cmd --zone=public --query-port=80/tcp
        • 新增80端口
      • firewall-cmd --reload
        • 重启防火墙
      • reboot 重启centos
      • firewall-cmd --zone=public --list-all
        • 查看ports是否出现此端口,如果出现则配置成功
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值