download big file with limt upstream ,post file - php

on jumpstarter.io
i have project php
i want dowload file larger from server via HTTP [php]
file size limit = 30 MB for post file
i can't config http {} of the nginx.conf file normally located at /etc/nginx/nginx.conf:
and php.ini
Editable :
NginX Configuration
server {
listen 0.0.0.0;
root /var/www;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
# expires 2w;
# }
location ~* \\.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param PHP_VALUE "
display_errors=On
display_startup_errors=On
error_reporting=30719
";
}
}
Default: /etc/nginx/nginx.conf (can't edit)
user http;
worker_processes 2;
pid /var/run/nginx.pid;
daemon off;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 20m;
client_body_buffer_size 128k;
include /etc/nginx/mime.types;
# logging
access_log /var/log/nginx-access.log;
error_log /var/log/nginx-error.log;
# gzip
gzip on;
gzip_disable "msie6";
# vhost
include /etc/nginx/sites-enabled/*;
}
Anyone help me . thanks

Related

Server performance issue while running cakephp web application

Our application server is getting down or slow randomly throughout the day, CakePHP 2 application with Mysql is running on this server. We have some cronjobs set up and all are working perfectly.
This performance issue mostly occurs at business time (Day time)
Server configuration: AWS instance t2.large, FreeBSD 10.3-RELEASE-p11, Disk space 20% free (30GB)
I go through many server logs as well as application logs like below
Nginx error log (Few lines from the log)
2020/04/30 23:04:57 [info] 66440#101049: *71645 client closed connection while waiting for request, client: XX.XX.XX.XX, server: 0.0.0.0:80
2020/04/30 23:05:01 [info] 66440#101049: *71820 kevent() reported that client XX.XX.XX.XX closed keepalive connection
2020/04/30 23:05:42 [info] 66440#101049: *72494 peer closed connection in SSL handshake while SSL handshaking, client: XX.XX.XX.XX, server: 0.0.0.0:443
dmesg.today Log (Few lines)
sonewconn: pcb 0xfffff800a70cf7a8: Listen queue overflow: 193 already in queue awaiting acceptance (62 occurrences)
sonewconn: pcb 0xfffff800a70cf7a8: Listen queue overflow: 193 already in queue awaiting acceptance (57 occurrences)
sonewconn: pcb 0xfffff80115d9e7a8: Listen queue overflow: 193 already in queue awaiting acceptance (63 occurrences)
sonewconn: pcb 0xfffff80115d9e7a8: Listen queue overflow: 193 already in queue awaiting acceptance (126 occurrences)
HTOP outcome
PHP-fpm: pool www, sometimes consumes 100% of CPU and memory
NodePing Alert (Receiving continuous notification in day time)
failed the HTTP check. It is down as of Thu Apr 30 2020 12:29:09 GMT-0700.Timeout.
HTTP is back up after being down for 4 minutes as of Thu Apr 30 2020 23:28:19 GMT-0700.
Nginx.conf file
user www;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_header_timeout 3000;
client_body_timeout 3000;
fastcgi_read_timeout 3000;
client_max_body_size 32m;
fastcgi_buffers 8 128k;
fastcgi_buffer_size 128k;
server_name_in_redirect on;
server_names_hash_bucket_size 64;
server_names_hash_max_size 8192;
#access_log logs/access.log main;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
include /etc/nginx/ssl/*.conf;
server {
listen 80;
autoindex off;
server_name localhost;
add_header X-Frame-Options "SAMEORIGIN";
root /usr/local/www/html/webroot;
index index.html index.php;
# redirect server error pages to the static page /50x.html
location / {
# try_files $uri $uri/ /index.php?$uri&$args;
# set $new_uri $uri;
# try_files $uri $uri/ /index.php?$args;
try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
#fastcgi_param PATH_INFO $new_uri;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass /var/run/php5-fpm.sock;
fastcgi_read_timeout 300;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50.html {
root /etc/nginx/html;
}
location ~ /(\.ht|\.user.ini|\.git|\.hg|\.bzr|\.svn) {
deny all;
}
}
# HTTPS server
#
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name *.XXXX.com;
ssl on;
ssl_certificate /XXXXX.crt;
ssl_certificate_key /XXXXX.key;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1.1 TLSv1.2; # Dropping
root /usr/local/www/html/webroot;
index index.html index.php;
# redirect server error pages to the static page /50x.html
location / {
# try_files $uri $uri/ /index.php?$uri&$args;
# set $new_uri $uri;
# try_files $uri $uri/ /index.php?$args;
try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 3000;
}
location = /favicon.ico { log_not_found off; access_log off;}
location = /robots.txt { log_not_found off; access_log off;}
location ~ /.well-known { allow all; }
}
##
# Cache Proxy
##
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=512m;
proxy_temp_path /var/tmp;
}
below are Some CPU utilization screens from AWS console
Above are some of my findings to found the issue, but I don't know what is causing poor server performance. Please suggest
UPDATE
I observe that in business hours (TTFB) is taking too much time (20 -25 sec)
I check the log of Mysql queries running on that page took Total Time: 1441 ms
So, Something else taking up time to load the page.
HTOP outcome at that time

Disable CSS and Javascript cache in nginx server created with Docker

I've got nginx server created with Docker. When I'm making changes to JS or CSS file, those appear after 30 - 60 seconds with force-refreshing in the browser (yes, browser cache is turned off). How to make them appear immediately? My system is Ubuntu 17.
nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
open_file_cache max=100;
client_max_body_size 4M;
}
daemon off;
And the server config:
server {
server_name l.site;
root /var/www/site;
index index.php;
location / {
try_files $uri #rewriteapp;
}
location #rewriteapp {
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($request_filename !~ "-l"){
set $rule_0 3$rule_0;
}
if ($rule_0 = "321"){
rewrite ^/(.*)$ /index.php?url=$1 last;
}
}
# from UPDATE #1 ->
location ~* \.(?:css|js)$ {
expires off;
# don't cache it
proxy_no_cache 1;
# even if cached, don't try to use it
proxy_cache_bypass 1;
}
# <- from UPDATE #1
location ~ \.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/site_error.log;
access_log /var/log/nginx/site_access.log;
}
UPDATE #1
Added this to server and still it is not showing me updated files in the browser just after code change.
location ~* \.(?:css|js)$ {
expires off;
# don't cache it
proxy_no_cache 1;
# even if cached, don't try to use it
proxy_cache_bypass 1;
}
UPDATE #2
Used THIS configuration, and still... didn't helped.
location / {
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires off;
}
Link to newest versions of files:
https://gist.github.com/ktrzos/1bbf2fd0161ce0e20541ccb18fe066a5
Try to disable cache using .htaccess. this is code from my live website. this should work.
<FilesMatch "\.(html|htm|js|css|php)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>
When using docker on VM (VirtualBox or so) change nginx.conf property sendfile to off
http {
server_tokens off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*;
open_file_cache max=100;
client_max_body_size 4M;
}

The nginx only load the index.php

I have a problem with my nginx configuration. We have a Vagrant box at the firm. In this vagrant we have LXC containers for services like nginx container, php-fpm container, memcached container, mysql container... These are connecting to each other, nginx use php-fpm, php-fpm use memcached and mysql. I have access to the nginx outside the vagrant through https. Here is my nginx configuration:
nginx.conf:
user nginx nginx;
worker_processes 4;
pid /var/run/nginx.pid;
worker_rlimit_nofile 1024;
events {
worker_connections 2048;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
access_log "/var/log/nginx/access.log";
error_log "/var/log/nginx/error.log";
keepalive_timeout 120;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
deault.conf:
server {
listen *:80;
server_name vagrant.ceg.com;
return 301 'https://$server_name$request_uri';
}
https.conf:
server {
listen *:443;
ssl on;
ssl_certificate ....crt;
ssl_certificate_key ....key;
server_name vagrant.ceg.com www.vagrant.ceg.com;
root "/srv/www";
index index.php;
location / {
autoindex on;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param ENVIRONMENT dev;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
if (-f $request_filename) {
fastcgi_pass 192.168.42.114:9000;
}
}
}
When I open it in the browser I get the index.php, but very slowly, and I got same errors on the console like this:
https://www.vagrant.ceg.com/cdn/util/scale/320/320/dev-employer-images/0636443e3076af9d24ba2b1711f57fb47b60f289.jpg Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

How to create virtual host in nginx server ? and ajax call

I am using WT-NMP software with combination of php,mysql and ngnix server.
worker_processes 1;
events {
worker_connections 1024;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
ssi off;
#Timeouts
client_body_timeout 5;
client_header_timeout 5;
keepalive_timeout 25 25;
send_timeout 15s;
resolver_timeout 3s;
#Directive sets timeout period for connection with FastCGI-server. It should be noted that this value can't exceed 75 seconds.
fastcgi_connect_timeout 5s;
#Directive sets the amount of time for upstream to wait for a fastcgi process to send data. Change this directive if you have long running fastcgi processes that do not produce output until they have finished processing. If you are seeing an upstream timed out error in the error log, then increase this parameter to something more appropriate.
fastcgi_read_timeout 40s;
#Directive specifies request timeout to the server. The timeout is calculated between two write operations, not for the whole request. If no data have been written during this period then serve closes the connection.
fastcgi_send_timeout 15s;
fastcgi_buffers 8 32k;
fastcgi_buffer_size 32k;
#fastcgi_busy_buffers_size 256k;
#fastcgi_temp_file_write_size 256k;
open_file_cache off;
#php max upload limit cannot be larger than this
client_max_body_size 8m;
####client_body_buffer_size 1K;
client_header_buffer_size 1k;
large_client_header_buffers 2 1k;
types_hash_max_size 2048;
include nginx.mimetypes.conf;
default_type text/html;
##
# Logging Settings
##
access_log "c:/wt-nmp/log/nginx_access.log";
error_log "c:/wt-nmp/log/nginx_error.log" warn; #debug or warn
log_not_found on; #enables or disables messages in error_log about files not found on disk.
rewrite_log off;
#Leave this off
fastcgi_intercept_errors off;
gzip off;
index index.php index.htm index.html;
server {
listen 127.0.0.1:80 default_server;
listen 127.0.0.1:8080;
#listen [::1]:80 ipv6only=on;
server_name mylocalhost;
root "c:/wt-nmp/www/projectname";
autoindex on;
error_log "c:/wt-nmp/log/nginx_error.log";
allow 127.0.0.1;
#allow ::1;
deny all;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
#tools are now served from wt-nmp/include/tools/
location ~ ^/tools/.*\.php$ {
root "c:/wt-nmp/include";
try_files $uri =404;
include nginx.fastcgi.conf;
fastcgi_pass php_farm;
}
location ~ ^/tools/ {
root "c:/wt-nmp/include";
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_farm;
include nginx.fastcgi.conf;
}
}
include domains.d/*.conf;
include nginx.phpfarm.conf;
}
when I am trying to access with "mylocalhost" its working fine when I am firing an event and call ajax method . It is giving page not found message
WT-NMP - portable Nginx Mysql Php development stack for Windows README.md states:
Starting only one PHP-CGI server with wt-nmp.exe --phpCgiServers=1 will result in slow ajax requests since Nginx will not be able to process PHP scripts simultaneous.
So, make sure you use the latest version of WT-NMP and choose at least 3 PHP-CGI servers.

$_SERVER['REMOTE_ADDR'] doesn't work with php-fpm and nginx

I don't know why with nginx this variable $_SERVER['REMOTE_ADDR'] doesn't echo an IP. On every other web server it works as it should.
Any suggestions?
I suspect it has something to do with the interface between nginx (the webserver) and fastcgi, which is the API in which PHP is running.
According to your info provided, the Server API is: FPM/FastCGI
I suggest you take a hard look at the details of how PHP is installed with nginx (you have not provided any).
If you do not require the performance of nginx, then you may find a pragmatic solution is to just use apache. I use nginx as a reverse proxy in front of apache, but that introduces some additional issues with getting the REMOTE_ADDR passed to PHP (notably, mod_rpaf).
Good luck!
#Michael, here is a project I maintain which provides the proper fastcgi parameters for interfacing Nginx with FPM. Hope it helps.
fastcgi_params on Github
These are from the conf file from nginx
user http;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server {
listen 80;
server_name www.fireangel.ro fireangel.ro;
access_log /var/log/nginx/localhost.access.log;
Default location
location / {
root /var/www/html/fireangel.ro/public_html;
index index.php;
}
Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www/html/fireangel.ro/public_html;
}
Parse all .php file in the /srv/http directory
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/fireangel.ro/public_html$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
}
upstream backend {
server 127.0.0.1:9000;
}
}

Categories