linux系統上部署vue專案
阿新 • • 發佈:2021-10-28
1.npm run build 進行打包---會生成一個dist檔案
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_connections1024; } 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、每個指令必須有分號結束。