亲测:LNMP环境下,解决项目缓冲慢、502以及配置https的问题

时间:2022-09-29 14:37:12

在做的项目在nginx下访问缓冲时间过长,明显比apache下访问蛮11倍有余,

亲测:LNMP环境下,解决项目缓冲慢、502以及配置https的问题

解决办法:

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

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

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

 server {
listen ;
server_name 你的域名;
index index.html index.htm index.php;
root /yjdata/www/www/tp5_houtai/public;
error_page /.html; location / {
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$ last;
break;
}
#nginx反向代理 此处是解决缓冲慢的重点部分
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;
#autoindex on;
}
#location ~ \.php$ {
# fastcgi_pass 127.0.0.1:;
# include fastcgi.conf;
#}
location ~ \.php(.*)$ {
#配置404
try_files $uri =;
#此处是9000或者10000根据自己服务器实际情况改 我这里是10000
# fastcgi_pass 127.0.0.1:;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
include fastcgi.conf;
}
}

配置https 1 # HTTPS server

     #
server {
listen ssl;
server_name 你的域名;
root /usr/share/nginx/html/wxssgsrz; index index.html index.htm;
#相关证书
10 ssl_certificate cert/214757705190741.pem;
11 #相关证书
12 ssl_certificate_key cert/214757705190741.key; ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1. TLSv1.;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html/项目名称;
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$ last;
break;
}

          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;

         }

         location ~ .*\.(php|php5)?$ {
root /usr/share/nginx/html/项目名称;
          #此处是9000或者10000根据自己服务器实际情况改 我这里是10000
          fastcgi_pass 127.0.0.1:10; 
         fastcgi_index index.php;
        fastcgi_param HTTPS on;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
34         #new line
         include fastcgi.conf;
      }
     } #此处是把http强制转成https的配置 及访问http会自动跳转到https对应地址上
server {
   listen ;
  server_name wx.ssgsrz.com;
   rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

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

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