Mon but est de faire un moyen de générer automatiquement SSL certs pour les personnes qui veulent ajouter leur site à mon service CDN (https://hostcloak.com)Comment faire un exécuter script bash via nginx/php
Voici le script fonctionne via SSH, mais pas lorsque je tente de l'exécuter via php
exec("sudo sh /var/autossl $domain 2>&1", $output);
Voici le script bash:
#!/bin/bash
domain=$1
# Set up config file.
cat > /etc/nginx/sites/$domain.conf <<EOF
server {
listen 80;
server_name *.$domain;
root /var/www/$domain;
}
EOF
nginx -s reload
#########################################
set -o nounset
set -o errexit
mkdir -p /var/www/$domain
# Set up config file.
mkdir -p /etc/letsencrypt
cat > /etc/letsencrypt/cli.ini <<EOF
# Uncomment to use the staging/testing server - avoids rate limiting.
# server = https://acme-staging.api.letsencrypt.org/directory
# Use a 4096 bit RSA key instead of 2048.
rsa-key-size = 4096
# Set email and domains.
email = [email protected]
domains = $domain
# Text interface.
text = True
# No prompts.
non-interactive = True
# Suppress the Terms of Service agreement interaction.
agree-tos = True
# Use the webroot authenticator.
authenticator = webroot
webroot-path = /var/www/$domain
EOF
# Obtain cert.
certbot-auto certonly
# Set up daily cron job.
CRON_SCRIPT="/etc/cron.daily/certbot-renew"
cat > "${CRON_SCRIPT}" <<EOF
#!/bin/bash
#
# Renew the Let's Encrypt certificate if it is time. It won't do anything if
# not.
#
# This reads the standard /etc/letsencrypt/cli.ini.
#
# May or may not have HOME set, and this drops stuff into ~/.local.
export HOME="/root"
# PATH is never what you want it it to be in cron.
export PATH="\${PATH}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
certbot-auto --no-self-upgrade certonly
# If the cert updated, we need to update the services using it. E.g.:
if service --status-all | grep -Fq 'apache2'; then
service apache2 reload
fi
if service --status-all | grep -Fq 'httpd'; then
service httpd reload
fi
if service --status-all | grep -Fq 'nginx'; then
service nginx reload
fi
EOF
chmod a+x "${CRON_SCRIPT}"
#####################################
# Set up config file.
cat > /etc/nginx/sites/$domain.conf <<EOF
server {
listen 80;
server_name *.$domain;
location/{
proxy_set_header x-real-IP \$remote_addr;
proxy_set_header x-forwarded-for \$proxy_add_x_forwarded_for;
proxy_set_header host \$host;
proxy_pass http://google.com;
}
}
server {
listen 443;
server_name *.$domain;
ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location/{
proxy_set_header x-real_IP \$remote_addr;
proxy_set_header x-forwarded-for \$proxy_add_x_forwarded_for;
proxy_set_header host \$host;
proxy_pass http://google.com;
}
}
EOF
nginx -s reload
"AutoSSL" fonctionne lorsqu'il est directement utilisé par la console ssh, mais lorsque je tente via la fonction exec php, il est dit "command not found" pour "nginx -s reload"
Alors ma question est la suivante: Comment puis-je parvenir via PHP (il doit être automatisé par mon site)
J'ai essayé cela, mais j'ai ceci: Array ([0] =>/usr/local/bin/autossl: ligne 6: /etc/nginx/sites/yoyyo.com.conf: autorisation refusée [1] =>/usr/local/bin/autossl: ligne 14: nginx: commande non found [2] => Demande de réexécution/usr/local/bin/certbot-auto avec les privilèges root ... [3] => [4] => Nous espérons avoir reçu la conférence habituelle du système local [5] => Administrateur Il se résume généralement à ces trois choses: [6] => [7] => # 1) Respecter la vie privée des autres. [8] => # 2) Réfléchissez avant de taper. [9] => # 3) Avec une grande puissance vient une grande responsabilité. [10] => [11] => sudo: aucun tty présent un ... – John
Hmmm, la première erreur est probablement parce que php/nginx ont d'autres privilèges que votre utilisateur, la seconde cause parce que la commande nginx n'est pas dans le chemin de php/nginx bash –
Comment l'ajouter au chemin de php/nginx bash? – John