Bonjour,
Voici comment mettre votre serveur Hugo en place.
Installer les dépendances :
yum install -y nginx wget hugo git
systemctl enable --now nginx
Configurer l'utilisateur Hugo :
mkdir -p /opt/hugo
groupadd -r hugo
useradd -r -g hugo -d /opt/hugo -s /sbin/nologin hugo
cd /opt/hugo
git clone https://github.com/gohugoio/hugoDocs
chown -R hugo: /opt/hugo
Configurer Hugo :
nano /opt/hugo/hugoDocs/run.sh
#!/bin/bash
H_PORT="1313"
H_WEBSITE="https://hugo.my_domain.com/"
H_IP="127.0.0.1"
# Move to the directory
cd "$(dirname "$(realpath "$0")")" || exit
if ! netstat -tnlp | grep 1313 > /dev/null 2>&1; then
echo "Port 1313 is not Used"
else
echo "Port 1313 is Used"
exit 0
fi
# Run the server
/usr/bin/git pull || exit
hugo server --appendPort "${H_PORT}" -b "${H_WEBSITE}" --bind "${H_IP}"
exit 0
chmod +x /opt/hugo/hugoDocs/run.sh
Configurer Hugo Service :
nano /etc/systemd/system/hugo.service
[Unit]
Description=hugo
After=network.target
After=nginx.service
[Service]
WorkingDirectory=/opt/hugo/hugoDocs/
User=hugo
Group=hugo
Type=simple
ExecStart=/opt/hugo/hugoDocs/run.sh
RestartSec=120
Restart=always
[Install]
WantedBy=multi-user.target
systemctl enable --now hugo
Configurer Nginx :
nano /etc/nginx/conf.d/hugo.conf
Exemple :
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name hugo.my_domain.com;
access_log /var/log/nginx/hugo-access.log;
error_log /var/log/nginx/hugo-error.log error;
## The default `client_max_body_size` is 1M, this might not be enough for some posters, etc.
client_max_body_size 200M;
# SSL Configuration
ssl_certificate /root/.ssl/hugo.my_domain.com.crt;
ssl_certificate_key /root/.ssl/hugo.my_domain.com.key;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ecdh_curve secp384r1;
ssl_prefer_server_ciphers off;
ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384";
ssl_session_timeout 10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 9.9.9.9;
resolver_timeout 5s;
# See https://hstspreload.org/ before uncommenting the line below.
# add_header Strict-Transport-Security "max-age=15768000; preload;";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header Content-Security-Policy "frame-ancestors 'self'";
add_header X-Frame-Options DENY;
add_header Referrer-Policy same-origin;
location / {
proxy_pass http://localhost:1313;
proxy_set_header Host $host;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Host $http_host;
}
}
systemctl reload nginx
Voilà vous avez un serveur hugo qui fonctionne