Important
Make sure the Nginx temporary folder is the same used by the web application ( properties upload.temp )
to prevent lots of waste of space and other issues...
Go here for the latest version or...
Version 1.8 -> http://nginx.org/download/nginx-1.8.1.tar.gz
cd ~
wget http://nginx.org/download/nginx-1.8.1.tar.gzExtract the nginx archive where you want with:
tar -xvf nginx-1.8.1.tar.gzFor Centos:
sudo yum install -y httpd-devel httpd-tools pcre perl pcre-devel zlib zlib-devel openssl-devel php-fpmFor Ubuntu:
sudo apt-get install libpcre3-dev zlib1g-dev libssl-dev make apache2-utils php5-fpmExecute the following commands in sequence inside the nginx folder:
./configure \
--user=nginx \
--group=nginx \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre \
--with-file-aio \
--with-http_realip_module
make
sudo make installNow that Nginx is installed we need to configure the file upload handler. We need to execute a script that will do some configuration for us.
From this repository take the following file:
sudo wget https://raw.githubusercontent.com/emawind84/nginx-upload-handler-conf/master/nginx_configure.sh \
-O /etc/nginx/configure.shLet's execute the script:
cd /etc/nginx
sudo chmod +x configure.sh
sudo ./configureThis script should grab several files from the repository, test the configuration for errors and test a file upload on the server. If everything is ok you should see some instructions for starting, stopping and reloading nginx.:
...
nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:40
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Starting nginx server...
nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:40
https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
Start nginx using: nginx
Reload nginx using: nginx -s reload
Stop nginx using: nginx -s stopWe need to check the user running php service is the same runnig nginx service and make sure this user has access to the web folder ( www or /var/www/html ) set in nginx configuration.
On Centos you need to edit the file /etc/php-fpm.d/www.conf:
user = www-data
group = www-dataOn Ubuntu I don't remember...
Make sure the service is running (probably not), check with:
ps -ef | grep phpif not start the service with:
sudo service php-fpm startor try with:
sudo systemctl start php-fpmCheck that the handler is working with the following commands:
$ sudo dd if=/dev/zero of=/tmp/test.tmp bs=512k count=1 >/dev/null 2>&1
$ sudo curl --user ngxupload:ngxupload --data-binary '@/tmp/test.tmp' http://127.0.0.1:8180/upload
{"fileId":"0046678708","fileEdmsId":"","filePath":"/tmp/0046678708","contentType":"application/octet-stream;charset=UTF-8"}Important
Make sure the modules proxy_module and proxy_http_module are installed before continuing.
Verify the following directives are present inside the main Apache configuration file:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.soAdd the following Proxy configuration to the Apache VirtualHost:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
...
# FILE UPLOAD HANDLER
<LocationMatch '/upload'>
<IfModule security2_module>
SecRuleEngine Off
</IfModule>
ProxyPass "http://127.0.0.1:8180/upload"
ProxyPassReverse "http://127.0.0.1:8180/upload"
</LocationMatch>Important
NOT REQUIRED ANYMORE IF USING PHP REQUEST
Because the file handler need to do a request on http://127.0.0.1/Common/TemporaryFile/fastupload.action we need to add the following default jkMount to the default VirtualHost if it is present:
# default host
<VirtualHost _default_:80>
ServerName 127.0.0.1
DocumentRoot "/tmp"
...
# [IMPORTANT] nginx file upload result handler
jkMount /Common/TemporaryFile/* worker1
</VirtualHost>Change the worker1 with the actual one used on the server.
Important
There is a problem on big file upload with the following error:
[error] (103)Software caused connection abort: proxy: pass request body failed to 127.0.0.1:50000 (127.0.0.1)
[error] proxy: pass request body failed to 127.0.0.1:50000 (127.0.0.1) from 1.1.1.1.1 ()To resolve this error add the following directives inside the Apache configuration file:
SetEnv proxy-sendchunked 1
SetEnv proxy-sendchunks 1
SetEnv downgrade-1.0 1
SetEnv proxy-sendcl 1Remember to add the following property to the project system configuration file:
system.upload.handler=nginxRestart the application and do some upload test on WebHard.