Nginx部署vue項(xiàng)目配置
- 記錄一下 Nginx部署vue項(xiàng)目
user root;
worker_processes 1;
error_log /home/hongtu/web/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;文章來源:http://www.zghlxwxcb.cn/news/detail-507885.html
#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 80; # 此處填寫你的端口
gzip on; # 開啟gzip
gzip_min_length 1k; # 小于1k的不壓縮
gzip_comp_level 9; # 壓縮等級
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 壓縮類型
gzip_vary on; # 啟用壓縮
gzip_disable "MSIE [1-6]\.";
server_name 192.168.0.1; # 此處填寫你的服務(wù)器地址
charset utf-8; # 此處填寫你的編碼
#root /usr/share/nginx/html; # 此處填寫你的項(xiàng)目路徑
#index index.html index.htm index.nginx-debian.html; # 此處填寫你的首頁
#fastcgi_connect_timeout 6000s; # 此處填寫你的超時(shí)時(shí)間
#fastcgi_send_timeout 6000s; # 此處填寫你的超時(shí)時(shí)間
#fastcgi_read_timeout 6000s; # 此處填寫你的超時(shí)時(shí)間
location / {
root /usr/share/nginx/html/dist;
try_files $uri $uri/ /index.html;
index index.html;
proxy_pass http://0.0.0.0:9200; // 前端地址
add_header Access-Control-Allow-Origin *;
fastcgi_connect_timeout 6000s;
fastcgi_send_timeout 6000s;
fastcgi_read_timeout 6000s;
proxy_read_timeout 6000s;
}
# 反向代理,代理標(biāo)志后面要不要加/,要看最終發(fā)送的請求api在不在,和我們配置代理 pathRewrite差不多
location ^~ /api {
proxy_pass http://127.0.0.1:8888; # 此處填寫你的后端代
rewrite ^/api/(.*)$ /$1 break; # 如果指定的正則表達(dá)式與請求的URI匹配,則URI將按照替換字符串中的指定進(jìn)行更改。重寫指令按照它們在配置文件中出現(xiàn)的順序依次執(zhí)行
proxy_set_header Host $host; # 代理服務(wù)器會將請求頭中的host字段設(shè)置為代理服務(wù)器的地址
proxy_set_header X-Real-IP $remote_addr; # 允許對傳遞給代理服務(wù)器的請求頭重新定義或追加字段
proxy_set_header X-Real-Port $remote_port; #
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 客戶端請求報(bào)頭字段,其中添加了$remote_addr變量,用逗號分隔
#fastcgi_connect_timeout 6000s;
#fastcgi_send_timeout 6000s;
#fastcgi_read_timeout 6000s;
#proxy_read_timeout 6000s;
}
}
include servers/*;
# 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;
# location / {
# root html;
# index index.html index.htm;
# }
}文章來源地址http://www.zghlxwxcb.cn/news/detail-507885.html
到了這里,關(guān)于Nginx部署vue項(xiàng)目配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!