開門見山,網站請求反應速度慢首先考慮服務器問題。
我在開發中遇到的就是服務器實例限制cpu占用10%以內訪問正常,超出則限制訪問速度,也就是網站請求速度慢
具體和阿里工程師聊天截圖如下:
按照對方說的,升級了相關配置,然后重啟服務器,重啟web端的nginx和php,速度溜溜上來了;
另外也最好把下面幾條給做了
1增加nginx的upstream,其中upstream中為php-cgi的地址;
2利用nginx作為反向代理,分支法解決並發量;
3增加php-cgi的進程數,(這里會受到機器資源的限制,因此,也並不能無限增加)
我這里使用了反向代理這各辦法解決了相關問題
下面把具體解決辦法放在下面,順便把nginx下配置項目的配置貼出來,供大家使用
1 server { 2 listen 80; 3 server_name 你的域名; 4 index index.html index.htm index.php; 5 root /yjdata/www/www/tp5_houtai/public; 6 error_page 404 /404.html; 7 8 location / { 9 index index.php index.html index.htm; 10 if (!-e $request_filename) { 11 rewrite ^(.*)$ /index.php?s=$1 last; 12 break; 13 } 14 #nginx反向代理 此處是解決緩沖慢的重點部分 15 proxy_read_timeout 300; 16 proxy_connect_timeout 300; 17 proxy_set_header X-Real-IP $remote_addr; 18 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 19 proxy_set_header Host $http_host; 20 proxy_redirect off; 21 #autoindex on; 22 } 23 #location ~ \.php$ { 24 # fastcgi_pass 127.0.0.1:10000; 25 # include fastcgi.conf; 26 #} 27 location ~ \.php(.*)$ {
#配置404 28 try_files $uri =404;
#此處是9000或者10000根據自己服務器實際情況改 我這里是10000 29 # fastcgi_pass 127.0.0.1:9000; 30 fastcgi_pass 127.0.0.1:10000; 31 fastcgi_index index.php; 32 fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; 33 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 34 fastcgi_param PATH_INFO $fastcgi_path_info; 35 fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 36 include fastcgi_params; 37 include fastcgi.conf; 38 } 39 }
配置https 1 # HTTPS server
2 # 3 server { 4 listen 443 ssl; 5 server_name 你的域名; 6 root /usr/share/nginx/html/wxssgsrz; 7 8 index index.html index.htm; 9 #相關證書 10 ssl_certificate cert/214757705190741.pem; 11 #相關證書 12 ssl_certificate_key cert/214757705190741.key; 13 14 ssl_session_timeout 5m; 15 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 16 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 17 ssl_prefer_server_ciphers on; 18 location / { 19 root /usr/share/nginx/html/項目名稱; 20 index index.html index.htm index.php; 21 if (!-e $request_filename) { 22 rewrite ^(.*)$ /index.php?s=$1 last; 23 break; 24 }
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
25 } 26 27 location ~ .*\.(php|php5)?$ { 28 root /usr/share/nginx/html/項目名稱;
#此處是9000或者10000根據自己服務器實際情況改 我這里是10000
29 fastcgi_pass 127.0.0.1:10000;
30 fastcgi_index index.php;
31 fastcgi_param HTTPS on;
32 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
33 include fastcgi_params;
34 #new line
35 include fastcgi.conf;
36 }
37 }
38
39 #此處是把http強制轉成https的配置 及訪問http會自動跳轉到https對應地址上
40 server {
41 listen 80;
42 server_name wx.ssgsrz.com;
43 rewrite ^/(.*) https://$server_name$request_uri? permanent;
44 }
好了 多余的不說了 ,大家復制拿去用就是了
謝謝大家瀏覽到這里~~~