linux系統上部署vue項目


1.npm run build 進行打包---會生成一個dist文件 注意vue上面配置的反向代理是不生效的
2.linux安裝nginx反向代理---然后在nginx.conf配置文件中配置

  nginx配置中重要的指令
   1.proxy_pass

#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       4433;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / { root /usr/local/nginx/opt/zz-mms; try_files $uri $uri/ =404; # 解決刷新報404的問題 index index.html index.htm; } 
        location /api/{ proxy_pass http://10.10.40.187/;
            proxy_cookie_path /api/ /; proxy_set_header Host $http_host; # required for docker client's sake
            proxy_set_header  X-Real-IP         $remote_addr; # pass on real client's IP
            proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 900; }

        #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;
    #    }
    #}
}






########### 每個指令必須有分號結束。################# #user administrator administrators; #配置用戶或者組,默認為nobody nobody。 #worker_processes 2; #允許生成的進程數,默認為1 #pid /nginx/pid/nginx.pid; #指定nginx進程運行文件存放地址 error_log log/error.log debug; #制定日志路徑,級別。這個設置可以放入全局塊,http塊,server塊,級別以此為:debug|info|notice|warn|error|crit|alert|emerg events { accept_mutex on; #設置網路連接序列化,防止驚群現象發生,默認為on multi_accept on; #設置一個進程是否同時接受多個網絡連接,默認為off #use epoll; #事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport worker_connections 1024; #最大連接數,默認為512 } http { include mime.types; #文件擴展名與文件類型映射表 default_type application/octet-stream; #默認文件類型,默認為text/plain #access_log off; #取消服務日志  log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定義格式 access_log log/access.log myFormat; #combined為日志格式的默認值 sendfile on; #允許sendfile方式傳輸文件,默認為off,可以在http塊,server塊,location塊。 sendfile_max_chunk 100k; #每個進程每次調用傳輸數量不能大於設定的值,默認為0,即不設上限。 keepalive_timeout 65; #連接超時時間,默認為75s,可以在http,server,location塊。 upstream mysvr { server 127.0.0.1:7878; server 192.168.10.121:3333 backup; #熱備 } error_page 404 https://www.baidu.com; #錯誤頁 server { keepalive_requests 120; #單連接請求上限次數。 listen 4545; #監聽端口 server_name 127.0.0.1; #監聽地址  location ~*^.+$ { #請求的url過濾,正則匹配,~為區分大小寫,~*為不區分大小寫。 #root path; #根目錄 #index vv.txt; #設置默認頁 proxy_pass http://mysvr; #請求轉向mysvr 定義的服務器列表 deny 127.0.0.1; #拒絕的ip allow 172.18.5.54; #允許的ip  } } }





上面是nginx的基本配置,需要注意的有以下幾點:

 
         

1、幾個常見配置項:

 
         
  • 1.$remote_addr 與 $http_x_forwarded_for 用以記錄客戶端的ip地址;
  • 2.$remote_user :用來記錄客戶端用戶名稱;
  • 3.$time_local : 用來記錄訪問時間與時區;
  • 4.$request : 用來記錄請求的url與http協議;
  • 5.$status : 用來記錄請求狀態;成功是200;
  • 6.$body_bytes_s ent :記錄發送給客戶端文件主體內容大小;
  • 7.$http_referer :用來記錄從那個頁面鏈接訪問過來的;
  • 8.$http_user_agent :記錄客戶端瀏覽器的相關信息;
 
         

2、驚群現象:一個網路連接到來,多個睡眠的進程被同時叫醒,但只有一個進程能獲得鏈接,這樣會影響系統性能。

 
         

3、每個指令必須有分號結束。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM