vue前端分离打包部署
vue前端分离打包部署项目配置congig/index.js修改 assetsPublicPath: ‘./’运行npm run build 进行打包centos nginx配置下载安装包cd /usr/local/softwarewget http://nginx.org/download/nginx-1.6.2.tar.gz下载依赖库yum inst...
·
vue前端分离打包部署
项目配置
- congig/index.js
- 修改 assetsPublicPath: ‘./’
- 运行npm run build 进行打包
centos nginx配置
-
下载安装包
- cd /usr/local/software
- wget http://nginx.org/download/nginx-1.6.2.tar.gz
-
下载依赖库
- 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
-
解压安装
- tar -zxvf nginx-1.6.2.tar.gz -C /usr/local
- (local这个目录类似于Windows的program目录,所以一些软件可以都安装在这里)
- tar -zxvf nginx-1.6.2.tar.gz -C /usr/local
-
配置configure
- cd /usr/local/nginx-1.6.2
- ./configure --prefix=/usr/local/nginx
-
编译安装
- make
- make install
-
启动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
-
查看nginx进程
- ps aux | grep nginx
-
nginx开机自启动设置
- rc.local增加启动代码
- vi /etc/rc.local
- /usr/local/nginx/sbin/nginx
- 更改权限
- chmod 755 rc.local
- rc.local增加启动代码
前端部署Nginx配置
- 把打包好的文件放在centos系统下的nginx文件目前里面
- /usr/local/nginx
- 进入/usr/local/nginx/conf文件夹 配置nginx.conf
- 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;
# }
#}
}
- 重启nginx
部署完毕可能出现的问题
- 外部访问不了,但是虚拟机能访问(无法打开到主机的连接。 在端口 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是否出现此端口,如果出现则配置成功
- firewall-cmd --zone=public --list-all
- 造成原因:firewall防火墙原因
更多推荐
已为社区贡献2条内容
所有评论(0)