久久久久久久国产免费看-久久久久久久国产视频-久久久久久久久a免费-久久久久久久久国产-久久久久久久久久爱

搜索
網站建設,網站優化,網絡營銷,app開發,小程序開發,全網營銷

400-825-2717互聯網開發&推廣服務提供商

與我們合作

我們專注:網站策劃設計、網絡輿論監控、網站優化及網站營銷、品牌策略與設計
主營業務:網站建設、移動端微信小程序開發、APP開發、網絡運營、云產品·運維解決方案

有一個品牌項目想和我們談談嗎?

您可以填寫右邊的表格,讓我們了解您的項目需求,這是一個良好的開始,我們將會盡快與您取得聯系。當然也歡迎您給我們寫信或是打電話,讓我們聽到您的聲音

您也可通過下列途徑與我們取得聯系:

地 址: 上海市長寧區華寧國際7L

電 話: 400-825-2717(咨詢專線)

電 話: 13054973230(售后客戶服務)

網 址: http://www.586918.cn

傳 真: 021-61488448

郵 箱: [email protected]

快速提交您的需求 ↓

Nginx常用配置

發布日期:2024-02-26 瀏覽次數:36673

一、基礎配置

  1. user                            root;

  2. worker_processes                1;


  3. events {

  4.   worker_connections            10240;

  5. }


  6. http {

  7.   log_format                    '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"';

  8.   include                       mime.types;

  9.   default_type                  application/octet-stream;

  10.   sendfile                      on;

  11.   #autoindex                    on;

  12.   #autoindex_exact_size         off;

  13.   autoindex_localtime           on;

  14.   keepalive_timeout             65;

  15.   gzip                          on;

  16.   gzip_disable                  "msie6";

  17.   gzip_min_length               100;

  18.   gzip_buffers                  4 16k;

  19.   gzip_comp_level               1;

  20.   gzip_types                  text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

  21.   gzip_types                    "*";

  22.   gzip_vary                     off;

  23.   server_tokens                 off;

  24.   client_max_body_size          200m;


  25.   server {

  26.     listen                      80 default_server;

  27.     server_name                 _;

  28.     return                      403 /www/403/index.html;

  29.   }


  30.   include                       ../serve/*.conf;

  31. }

復制代碼


二、隱藏 Nginx 版本信息

  1. http {

  2.   server_tokens         off;

  3. }

復制代碼



三、禁止ip直接訪問80端口

  1. server {

  2.   listen                80 default;

  3.   server_name           _;

  4.   return                500;

  5. }

復制代碼


四、啟動 web 服務 (vue 項目為例)

  1. server {

  2.   # 項目啟動端口

  3.   listen            80;

  4.   # 域名(localhost)

  5.   server_name       _;

  6.   # 禁止 iframe 嵌套

  7.   add_header        X-Frame-Options SAMEORIGIN;

  8.   

  9.   # 訪問地址 根路徑配置

  10.   location / {

  11.     # 項目目錄

  12.     root        html;

  13.     # 默認讀取文件

  14.     index           index.html;

  15.     # 配置 history 模式的刷新空白

  16.     try_files       $uri $uri/ /index.html;

  17.   }

  18.   

  19.   # 后綴匹配,解決靜態資源找不到問題

  20.   location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {

  21.     root           html/static/;

  22.   }

  23.   

  24.   # 圖片防盜鏈

  25.   location ~/static/.*\.(jpg|jpeg|png|gif|webp)$ {

  26.     root              html;

  27.     valid_referers    *.deeruby.com;

  28.     if ($invalid_referer) {

  29.       return          403;

  30.     }

  31.   }

  32.   

  33.   # 訪問限制

  34.   location /static {

  35.     root               html;

  36.     # allow 允許

  37.     allow              39.xxx.xxx.xxx;

  38.     # deny  拒絕

  39.     deny               all;

  40.   }

  41. }

復制代碼


五、PC端和移動端使用不同的項目文件映射

  1. server {

  2.   ......

  3.   location / {

  4.     root /home/static/pc;

  5.     if ($http_user_agent ~* '(mobile|android|iphone|ipad|phone)') {

  6.       root /home/static/mobile;

  7.     }

  8.     index index.html;

  9.   }

  10. }

復制代碼


六、一個web服務,配置多個項目 (location 匹配路由區別)

  1. server {

  2.   listen                80;

  3.   server_name           _;

  4.   

  5.   # 主應用

  6.   location / {

  7.     root                html/main;

  8.     index               index.html;

  9.     try_files           $uri $uri/ /index.html;

  10.   }

  11.   

  12.   # 子應用一

  13.   location ^~ /store/ {

  14.     proxy_pass          http://localhost:8001;

  15.     proxy_redirect      off;

  16.     proxy_set_header    Host $host;

  17.     proxy_set_header    X-Real-IP $remote_addr;

  18.     proxy_set_header    X-Forwarded-For

  19.     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

  20.   }

  21.   

  22.   # 子應用二

  23.   location ^~ /school/ {

  24.     proxy_pass          http://localhost:8002;

  25.     proxy_redirect      off;

  26.     proxy_set_header    Host $host;

  27.     proxy_set_header    X-Real-IP $remote_addr;

  28.     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

  29.   }

  30.   

  31.   # 靜態資源讀取不到問題處理

  32.   rewrite ^/api/profile/(.*)$ /(替換成正確路徑的文件的上一層目錄)/$1 last;

  33. }


  34. # 子應用一服務

  35. server {

  36.   listen                8001;

  37.   server_name           _;

  38.   location / {

  39.     root                html/store;

  40.     index               index.html;

  41.     try_files           $uri $uri/ /index.html;

  42.   }

  43.   

  44.   location ^~ /store/ {

  45.     alias               html/store/;

  46.     index               index.html index.htm;

  47.     try_files           $uri /store/index.html;

  48.   }

  49.   

  50.   # 接口代理

  51.   location  /api {

  52.     proxy_pass          http://localhost:8089;

  53.   }

  54. }


  55. # 子應用二服務

  56. server {

  57.   listen                8002;

  58.   server_name           _;

  59.   location / {

  60.     root                html/school;

  61.     index               index.html;

  62.     try_files           $uri $uri/ /index.html;

  63.   }

  64.   

  65.   location ^~ /school/ {

  66.     alias               html/school/;

  67.     index               index.html index.htm;

  68.     try_files           $uri /school/index.html;

  69.   }

  70.   

  71.   # 接口代理

  72.   location  /api {

  73.     proxy_pass          http://localhost:10010;

  74.   }

  75. }

復制代碼


七、配置負載均衡

  1. upstream my_upstream {

  2.   server                http://localhost:9001;

  3.   server                http://localhost:9002;

  4.   server                http://localhost:9003;

  5. }


  6. server {

  7.   listen                9000;

  8.   server_name           test.com;


  9.   location / {

  10.     proxy_pass          my_upstream;

  11.     proxy_set_header    Host $proxy_host;

  12.     proxy_set_header    X-Real-IP $remote_addr;

  13.     proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

  14.   }

  15. }

復制代碼


八、SSL 配置 HTTPS

  1. server {

  2.   listen                      80;

  3.   server_name                 <a  target="_blank">www.xxx.com</a>;

  4.   # 將 http 重定向轉移到 https

  5.   return 301 https://$server_name$request_uri;

  6. }


  7. server {

  8.   listen                      443 ssl;

  9.   server_name                 <a  target="_blank">www.xxx.com</a>;

  10.   ssl_certificate             /etc/nginx/ssl/www.xxx.com.pem;

  11.   ssl_certificate_key         /etc/nginx/ssl/www.xxx.com.key;

  12.   ssl_session_timeout         10m;

  13.   ssl_ciphers                 ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

  14.   ssl_protocols               TLSv1 TLSv1.1 TLSv1.2;

  15.   ssl_prefer_server_ciphers   on;

  16.   

  17.   location / {

  18.     root                    /project/xxx;

  19.     index                   index.html index.htm index.md;

  20.     try_files               $uri $uri/ /index.html;

  21.   }

  22. }

復制代碼



GO 知識
查看經典案例

TOP

QQ客服

免費電話

微信咨詢 在線咨詢 免費電話
獲取報價
您的稱呼:

*

您的電話:

*

您的郵箱:

*

提交 重置
重要的事情,電話里聊

接通客服

不方便的時候線上咨詢,在線等哦
主站蜘蛛池模板: 毛片三级在线观看 | 国产91在线免费观看 | 亚洲丶国产丶欧美一区二区三区 | 国产美女一区二区三区 | 在线播放成人高清免费视频 | 日韩精品亚洲人成在线播放 | 日韩欧一级毛片在线播无遮挡 | 国产日产欧美a级毛片 | 国产精品爱久久久久久久三级 | 国产成人精品亚洲2020 | 国产高清免费不卡观看 | 成人在线免费小视频 | 久久久久婷婷国产综合青草 | 日本特黄特色大片免费视频 | 精品国产第一页 | 亚洲成a人片在线网站 | 韩国深夜福利视频19禁在线观看 | 免费一区在线观看 | 成人免费在线 | 超清波多野结衣精品一区 | 免费一级a毛片 | 成人国产网站v片免费观看 成人国产视频在线观看 | 色视频在线免费观看 | 黄录像欧美片在线观看 | 手机看片国产免费现在观看 | 福利视频网址 | 国产在线精品一区二区不卡 | 久久er视频 | 欧美一级做a爰片久毛片 | 看一级特黄a大片国产 | 亚洲精品字幕一区二区三区 | 色婷婷视频| 国产一级三级三级在线视 | 日本三级免费网站 | 欧美一级片毛片免费观看视频 | 在线免费一区二区 | 国产亚洲欧美一区 | 国产成人禁片在线观看 | 国产成人亚洲精品久久 | 在线看片y | 美女色影院 |