• vue 部署windows nginx服务上


    vue 部署windows nginx服务上

    一.步骤:

    1.在nginx官网下载Windows稳定版本的nginx,提供官方下载地址:http://nginx.org/en/download.html
    2.安装包解压保存路径时不能含有中文,会报错
    3.打包vue项目(npm run build)将生成的dist目录拷贝到nginx的html目录下
    4.修改nginx的配置文件
    5.在nginx的安装目录启动nginx.exe,或使用start nginx命令启动项目。
    6.通过配置文件中的ip和端口访问vue项目

    二.配置nginx:

    #user  nobody;
    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  on;
    
        server {
              
                
            listen       8200; #前端访问时需要的端口
            server_name  192.168.0.105;#前端访问时需要的ip,默认127.0.0.1或localhost
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html/dist;
                index  index.html index.htm;
                 #try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
                 #try_files $uri $uri/ /index.html; ---解决页面刷新404问题
            }
            #location ^~/api { 
            #     proxy_set_header Host $host;
            #     proxy_set_header X-Real-IP $remote_addr; 
            #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            #     proxy_buffering off;
            #     rewrite ^/api/(.*)$ /$1 break; 
            #     proxy_pass http://xxxxx:8080; 后端接口地址
            #}
            #location /api/ {
                #proxy_set_header X-Real-IP $remote_addr;
                #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                #proxy_set_header Host  $http_host;
                #proxy_set_header X-Nginx-Proxy true;
                #proxy_set_header Connection "";
                #proxy_pass http://xxxxx:8080;  #****后端接口地址
                #proxy_redirect default ;
            #}
            location ^~/api { 
                rewrite ^/api/(.*)$ /$1 break;
                proxy_pass http://xxxxx:8080;  #****后端接口地址
            }
    
    
            #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;
        #    }
        #}
    
    }

    三.常用命令:

    start nginx 启动
    
    nginx -s reload  刷新
    
    tasklist /fi "imagename eq nginx.exe"  查看所有的nginx进程
    
    taskkill /fi "imagename eq nginx.exe" /f  杀死所有nginx进程
  • 相关阅读:
    【2020Python修炼记】web框架之 Django自带的序列化组件/form组件
    【2020Python修炼记】web框架之数据批量插入/分页器
    3.栈与队列
    2.链表
    1.数组
    越来越少人用JQuery,但你就不学了吗?(4)
    越来越少人用JQuery,但你就不学了吗?(3)
    越来越少人用JQuery,但你就不学了吗?(2)
    越来越少人用JQuery,但你就不学了吗?(1)
    JS事件、Bom对象和Dom对象(4)(乐字节架构)
  • 原文地址:https://www.cnblogs.com/zlp520/p/14055141.html
Copyright © 2020-2023  润新知