LNMP环境下,解决项目缓冲慢、502以及配置https的问题
程序员文章站
2022-03-22 14:49:21
在做的项目在nginx下访问缓冲时间过长,明显比apache下访问蛮11倍有余, 解决办法: 1增加nginx的upstream,其中upstream中为php-cgi的地址; 2利用nginx作为反向代理,分支法解决并发量; 3增加php-cgi的进程数,(这里会受到机器资源的限制,因此,也并不能 ......
在做的项目在nginx下访问缓冲时间过长,明显比apache下访问蛮11倍有余,
解决办法:
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 }
好了 多余的不说了 ,大家复制拿去用就是了
谢谢大家浏览到这里~~~
下一篇: zblog常用到的几个标签介绍