HanG321 Blog

upload file on nginx – part 2: MySQL PAM and nginx config

MySQL PAM Config

set up database table and column name for username and password

# vim /etc/pam.d/nginx

auth required pam_mysql.so user=USERNAME_HERE \
  passwd=PASSWORD_HERE \
  host=HOSTNAME_HERE \
  db=DATABASE_HERE \
  table=TABLE_OR_VIEW_NAME_HERE \
  usercolumn=USERNAME_COLUMN \
  passwdcolumn=PASSWORD_COLUMN \
  crypt=0 sqllog=0
# repeat .... with config above
account required pam_mysql.so user=USERNAME_HERE \  ........    crypt=0 sqllog=0
# alternatively, to external config file
# account required pam_mysql.so config_file=/etc/pam_mysql.conf

 

in nginx config (/etc/nginx/nginx or /etc/nginx/conf.d/)

location /restricted {
  auth_pam              "Restricted Zone"
  auth_pam_service_name "nginx"
}

 

Upload module config

in nginx config (/etc/nginx/nginx or /etc/nginx/conf.d/)

location /upload{
  auth_pam              "Restricted Zone"
  auth_pam_service_name "nginx"

  upload_pass  /uploadHandler.php;
  # the location where the files are uploaded
  upload_store	/var/tmp/fuploads;
  upload_store_access user:rw group:rw all:r;
  upload_resumable on;
  upload_state_store /var/tmp/fuploads/state ;

  # Set specified fields in request body
  # the field data will be available through the superglobal $_POST[]
  upload_set_form_field "${upload_field_name}_name" $upload_file_name;
  upload_set_form_field "${upload_field_name}_content_type" $upload_content_type;
  upload_set_form_field "${upload_field_name}_path" $upload_tmp_path;

  upload_cleanup 400 404 499 500-505;
}

# pass the PHP scripts to FastCGI server
location ~ \.php$ {
  try_files $uri =404;
	fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
}

php file upload handler example can be found on https://github.com/blueimp/jQuery-File-Upload/wiki/Uploading-to-nginx-using-the-nginx-upload-module-with-php_handler and https://github.com/blueimp/jQuery-File-Upload/tree/master/server/php

Exit mobile version