Tag Archives: nginx

nginx allow only index.php

upstream _php {
server unix:/var/run/php-fpm/php-fpm.sock;
}

server {
server_name 192.168.1.100;

root /path/to/root;
index index.php;

include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
location / { deny all; }
location = / { }
location = /index.php { fastcgi_pass _php; }

location /phpmyadmin/ { }
location ~ ^/phpmyadmin/.*\.php$ { fastcgi_pass _php; }
}

FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client

File not found.
Make sure SCRIPT_FILENAME same location like root:

server {
server_name 192.168.1.100;
location / {
root /var/www/html;

location ~* \.php$ {
fastcgi_pass unix:/var/run/php/php.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
}

acme no root


useradd -m -d /var/lib/acme -s /usr/sbin/nologin acme
chmod 700 /var/lib/acme

mkdir -p /var/www/EXAMPLE.com/.well-known/acme-challenge
chown acme.acme /var/www/EXAMPLE.com/.well-known/acme-challenge
chmod 755 /var/www/EXAMPLE.com/.well-known/acme-challenge

location ~ /.well-known {
allow all;
root /var/www/EXAMPLE.com;
}

visudo
acme ALL=(ALL) NOPASSWD: /usr/sbin/service nginx reload

su - acme -s /bin/bash
export HOME=/var/lib/acme
cd /var/lib/acme

git clone https://github.com/acmesh-official/acme.sh.git
cd acme.sh
./acme.sh --install

cd /var/lib/acme
.acme.sh/acme.sh --issue -d EXAMPLE.com -w /var/www/EXAMPLE.com

./acme.sh --issue -w /var/www/EXAMPLE.com -d EXAMPLE.com -d www.EXAMPLE.com

ssl_certificate /etc/nginx/auth-acme/EXAMPLE.com.crt;
ssl_certificate_key /etc/nginx/auth-acme/EXAMPLE.com.key;
ssl_trusted_certificate /etc/nginx/auth-acme/EXAMPLE.com.ca;

service nginx reload