Skip to content

Instantly share code, notes, and snippets.

@mahradbt
Created June 3, 2018 17:16
Show Gist options
  • Save mahradbt/fd687a0ae725ce21d1d587a1bd64d5e8 to your computer and use it in GitHub Desktop.
Save mahradbt/fd687a0ae725ce21d1d587a1bd64d5e8 to your computer and use it in GitHub Desktop.
nginx config serve php and download pdf
server {
listen <port> ssl;
server_name <domain>;
ssl_certificate /etc/ssl/certs/cert.crt;
ssl_certificate_key /etc/ssl/private/cert.key;
access_log /home/<domain>/logs/<domain>.access.log main;
error_log /home/<domain>/logs/<domain>.error.log warn;
root /home/<domain>/public_html;
# download pdf only
#
location ~* /(.*\.pdf) {
types { application/octet-stream .pdf; }
default_type application/octet-stream;
}
location / {
try_files $uri $uri/ /index.php;
index index.php;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /home/<domain>/public_html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 10000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment