網(wǎng)站首頁 編程語言 正文
nginx常用配置conf
代理靜態(tài)文件
# 靜態(tài)文件 server { # 壓縮問價你配置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain text/css application/javascript application/json image/jpeg image/png image/gif; gzip_disable "MSIE [1-6]\."; gzip_vary on; listen 8088; server_name web_resources; root /data/nginx/static; # 開啟頁面文件顯示 autoindex on; location / { # add_header Cache-Control no-store; add_header Cache-Control "public,max-age=2592000"; add_header 'Access-Control-Allow-Origin' '*'; } }
配置VUE項目
server { listen 8071 ; listen [::]:8071 ; server_name zrzyweb; # 這里是網(wǎng)站的域名 location / { add_header 'Access-Control-Allow-Origin' $http_origin; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } root E:/data/vue/zrzy; # /vue/dist/ 打包后的dist目錄 try_files $uri $uri/ @router; # 指向下面的 @router否則會出現(xiàn) 404 index index.html index.htm; } # 對應(yīng)上面的 @router,主要Vue請求并不是真實路徑,無法找到文件,需要重定向到 index.html 中,然后交給路由處理 location @router { rewrite ^.*$ /index.html last; } }
配置接口代理
可以配置多個代理服務(wù)
# 接口服務(wù) server { listen 8090; server_name njzy.natapp1.cc; charset utf-8; location /project/ { 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_pass http://192.168.1.106:8080/; } location /one/ { 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_pass http://192.168.1.243:9000/; } }
完整nginx.conf配置文件
{ #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 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #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 { # 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 # 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 # 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; # vue server { listen 8071 ; listen [::]:8071 ; server_name zrzyweb; # 這里是網(wǎng)站的域名 # root /var/www/ec; # /vue/dist/ 打包后的dist目錄 add_header 'Access-Control-Allow-Origin' $http_origin; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; if ($request_method = 'OPTIONS') { add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } root E:/data/vue/zrzy; # /vue/dist/ 打包后的dist目錄 try_files $uri $uri/ @router; # 指向下面的 @router否則會出現(xiàn) 404 index index.html index.htm; # 對應(yīng)上面的 @router,主要Vue請求并不是真實路徑,無法找到文件,需要重定向到 index.html 中,然后交給路由處理 location @router { rewrite ^.*$ /index.html last; } # 靜態(tài)文件 server { #web_resources gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain text/css application/javascript application/json image/jpeg image/png image/gif; gzip_disable "MSIE [1-6]\."; gzip_vary on; listen 8088; server_name web_resources; root /data/nginx/static; autoindex on; location / { # add_header Cache-Control no-store; add_header Cache-Control "public,max-age=2592000"; add_header 'Access-Control-Allow-Origin' '*'; } # 接口服務(wù) server { listen 8090; server_name njzy.natapp1.cc; charset utf-8; location /project/ { 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_pass http://192.168.1.106:8080/; location /one/ { proxy_pass http://192.168.1.243:9000/; location /two/ { proxy_pass http://192.168.1.100:9000/; location /three/ { proxy_pass http://192.168.1.100:8085/; }
原文鏈接:https://blog.csdn.net/qq_36213352/article/details/123620620
相關(guān)推薦
- 2022-05-29 在Linux系統(tǒng)上安裝PostgreSQL數(shù)據(jù)庫_PostgreSQL
- 2022-04-17 將本地jar放到pom中被maven管理
- 2022-04-25 .Net?Core?Aop之IResourceFilter的具體使用_實用技巧
- 2022-06-14 nginx搭建NFS服務(wù)器的方法步驟_nginx
- 2022-12-09 C++輸出問題:保留兩位小數(shù)_C 語言
- 2023-03-15 pandas計算相關(guān)系數(shù)corr返回空的問題解決_python
- 2023-12-23 Vercel 部署本地項目
- 2022-11-19 詳解C語言內(nèi)核中的自旋鎖結(jié)構(gòu)_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支