经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 汇编语言 » 查看文章
解决网站请求速度慢的一些方法
来源:cnblogs  作者:子钦加油  时间:2018/10/16 9:31:21  对本文有异议

 

开门见山,网站请求反应速度慢首先考虑服务器问题。

我在开发中遇到的就是服务器实例限制cpu占用10%以内访问正常,超出则限制访问速度,也就是网站请求速度慢

具体和阿里工程师聊天截图如下:

 

 

 

按照对方说的,升级了相关配置,然后重启服务器,重启web端的nginx和php,速度溜溜上来了;

另外也最好把下面几条给做了

  1增加nginx的upstream,其中upstream中为php-cgi的地址;
  2利用nginx作为反向代理,分支法解决并发量;
  3增加php-cgi的进程数,(这里会受到机器资源的限制,因此,也并不能无限增加)

 

我这里使用了反向代理这各办法解决了相关问题

下面把具体解决办法放在下面,顺便把nginx下配置项目的配置贴出来,供大家使用

复制代码

  1.  1 server {
  2.  2         listen       80;
  3.  3         server_name  你的域名;
  4.  4         index index.html index.htm index.php;
  5.  5         root /yjdata/www/www/tp5_houtai/public;
  6.  6         error_page 404 /404.html;
  7.  7         
  8.  8         location / {
  9.  9             index index.php index.html index.htm;
  10. 10             if (!-e $request_filename) {
  11. 11                 rewrite  ^(.*)$  /index.php?s=$1  last;
  12. 12                 break;
  13. 13             }
  14. 14 #nginx反向代理 此处是解决缓冲慢的重点部分
  15. 15          22         }
  16. 23         #location ~ \.php$ {
  17. 24         #        fastcgi_pass 127.0.0.1:10000;
  18. 25         #       include fastcgi.conf;
  19. 26         #}
  20. 27         location ~ \.php(.*){
  21.               #配置404
  22. 28             try_files $uri =404;
  23.               #此处是9000或者10000根据自己服务器实际情况改 我这里是10000
  24. 29            # fastcgi_pass   127.0.0.1:9000;
  25. 30             fastcgi_pass   127.0.0.1:10000;
  26. 31             fastcgi_index  index.php;
  27. 32             fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
  28. 33             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  29. 34             fastcgi_param  PATH_INFO  $fastcgi_path_info;
  30. 35             fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
  31. 36             include        fastcgi_params;
  32. 37             include fastcgi.conf;
  33. 38         }
  34. 39 }

复制代码

配置https 1 # HTTPS server

复制代码

  1.  2     #
  2.  3     server {
  3.  4         listen       443 ssl;
  4.  5         server_name  你的域名;
  5.  6         root /usr/share/nginx/html/wxssgsrz;
  6.  7 
  7.  8         index index.html index.htm;
  8.  9         #相关证书
  9. 10         ssl_certificate   cert/214757705190741.pem;
  10. 11         #相关证书
  11. 12         ssl_certificate_key  cert/214757705190741.key;
  12. 13 
  13. 14         ssl_session_timeout 5m;
  14. 15         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  15. 16         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  16. 17         ssl_prefer_server_ciphers on;
  17. 18         location / {
  18. 19             root /usr/share/nginx/html/项目名称;
  19. 20             index index.html index.htm index.php;
  20. 21             if (!-e $request_filename) {
  21. 22                rewrite  ^(.*)$  /index.php?s=$1  last;
  22. 23                break;
  23. 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;

  1. 25         }
  2. 26         
  3. 27         location ~ .*\.(php|php5)?{
  4. 28               root  /usr/share/nginx/html/项目名称; 
  5.           #
  1. 29          fastcgi_pass 127.0.0.1:10000; 
  2. 30          fastcgi_index index.php; 
  3. 31          fastcgi_param HTTPS on; 
  4. 32          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
  5. 33          include fastcgi_params; 
  6. 34         #new line 
  7. 35          include fastcgi.conf; 
  8. 36        }
  9. 37      } 
  10. 38 
  11. 39 #此处是把http强制转成https的配置 及访问http会自动跳转到https对应地址上
  12. 40  server { 
  13. 41    listen 80; 
  14. 42    server_name wx.ssgsrz.com; 
  15. 43    rewrite ^/(.*) https://$server_name$request_uri? permanent; 
  16. 44 }

复制代码

 

好了  多余的不说了 ,大家复制拿去用就是了

谢谢大家浏览到这里~~~

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号