VUE配置打包部署服务器Nginx代理访问配置域名

简介: VUE配置打包部署服务器Nginx代理访问配置域名,解决vue路由在Nginx中刷新404的问题,解决打包后找不到 js、静态文件的问题

上传服务器有多种方式
第一种:github.com建立私有项目,现在免费开放,本地push到github,服务器从github再pull下来。
第二种:使用FTP软件上传,比如FileZilla等等。
第三种:服务器搭建Git自动化部署。
前两种适合小型项目,第三种适合团队协作规范开发。

打包之前配置文件
build/utils.js 配置解决打包后找不到静态文件的问题

publicPath: '../../',
AI 代码解读

11_34_37__07_12_2019

config/index.js 解决js文件找不到的问题

assetsPublicPath: './',
AI 代码解读

11_35_45__07_12_2019

终端输入npm run build 打包,生成dist文件夹
dist文件夹和package.json为同级目录,放到服务器上,可以用以上三种方法
配置Nginx代理访问配置域名,找到nginx.conf文件,注意空格该有就要有,没有就没有

vi /usr/local/nginx/conf/nginx.conf
AI 代码解读
user  www www;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

    server{
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

##start
    server {
        listen       80;
        server_name  www.centby.com;#设置域名
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        root /var/backstage/dist;#dist文件目录
        location / {
           # root   html;
            try_files $uri $uri/ @router;#history模式,解决vue路由在Nginx中刷新404的问题
             index  index.html index.htm;
         }
        location @router{
                rewrite ^.*$/ index.html last;
        }
        location ~ ^/api/ {
                rewrite ^/api/(.*)$ /$1 break;
                proxy_pass http://x.centby.com;
        }

        #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;
        }
    }
##end
    include vhost/*.conf;
}
AI 代码解读

重启Nginx服务

//进入目录
cd /usr/local/nginx/sbin
//测试
./nginx -t
//重启服务
./nginx -s reload
AI 代码解读

现在就可以访问了
13_52_58__07_12_2019

常用命令

//配置代理访问
vi /usr/local/nginx/conf/nginx.conf
//进入目录
cd /usr/local/nginx/sbin
//启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
//测试
./nginx -t
//重启服务
./nginx -s reload
//查看进程
ps -ef|grep nginx
//关闭并重启
kill -HUP <进程号>
//从容停止服务
kill -QUIT <进程号>
kill -TERM <进程号>
AI 代码解读
佀无极
+关注
目录
打赏
0
0
0
0
250
分享
相关文章
Nginx进程配置指令详解
Nginx进程配置指令主要包括:`worker_processes`设置工作进程数;`worker_cpu_affinity`绑定CPU核心;`worker_rlimit_nofile`设置最大文件描述符数量;`worker_priority`设置进程优先级;`worker_connections`设置最大连接数;`daemon`控制守护进程模式;`master_process`启用主进程模式;`pid`设置PID文件路径;`user`指定用户和组;`error_log`配置错误日志。这些指令在`nginx.conf`中配置,用于优化和控制Nginx的运行行为。
90 10
Nginx伪流媒体服务器搭建详细说明以及案例
Nginx伪流媒体服务器搭建步骤如下:1. 安装Nginx,根据系统选择命令;2. 编辑配置文件(/etc/nginx/nginx.conf),添加mp4相关设置;3. 创建视频目录/usr/share/nginx/html/videos并上传视频;4. 重启Nginx应用更改;5. 通过浏览器访问视频,如http://your_server_ip/videos/example.mp4。注意启用mp4模块,确保视频格式支持伪流媒体播放。
使用域名访问部署在ECS上的网站
本文为您介绍如何为网站配置域名并为域名配置HTTPS证书。
新手上云教程参考:阿里云服务器租用、域名注册、备案及域名解析流程图文教程
对于想要在阿里云上搭建网站或应用的用户来说,购买阿里云服务器和注册域名,绑定以及备案的流程至关重要。本文将以图文形式为您介绍阿里云服务器购买、域名注册、备案及绑定的全流程,以供参考,帮助用户轻松上手。
当你的nginx服务器和php服务器不在一起的时候,这个nginx 的root目录问题
两个服务器的网站代码目录需要对齐,docker容器里面也是一样
nginx配置证书和私钥进行SSL通信验证
nginx配置证书和私钥进行SSL通信验证
159 4
服务器数据恢复—nas中raid6阵列失效,存储无法访问的数据恢复案例
一台nas上共有14块硬盘组建了一组raid6磁盘阵列。 该nas在工作过程中,raid6阵列中硬盘出现故障离线,导致raid6阵列失效,nas无法正常访问。
阿里云服务器租用、注册域名、备案及域名解析完整流程参考(图文教程)
对于很多初次建站的用户来说,选购云服务器和注册应及备案和域名解析步骤必须了解的,目前轻量云服务器2核2G68元一年,2核4G4M服务器298元一年,域名注册方面,阿里云推出域名1元购买活动,新用户注册com和cn域名2年首年仅需0元,xyz和top等域名首年仅需1元。对于建站的用户来说,购买完云服务器并注册好域名之后,下一步还需要操作备案和域名绑定。本文为大家展示阿里云服务器的购买流程,域名注册、绑定以及备案的完整流程,全文以图文教程形式为大家展示具体细节及注意事项,以供新手用户参考。
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
191 5
使用Nginx搭建流媒体服务器
本文介绍了流媒体服务器的特性及各种流媒体传输协议的适用场景,并详细阐述了使用 nginx-http-flv-module 扩展Nginx作为流媒体服务器的详细步骤,并提供了在VLC,flv.js,hls.js下的流媒体拉流播放示例。
524 2
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等