|
| 1 | +# Nginx configuration example |
| 2 | +# @author Amaury Bouchard <amaury@amaury.net> |
| 3 | +# @copyright © 2024, Amaury Bouchard |
| 4 | +# @link https://www.temma.net/documentation/installation#doc-nginx-server |
| 5 | + |
| 6 | +# http://mysite.com |
| 7 | +server { |
| 8 | + listen 80; |
| 9 | + server_name mysite.com; |
| 10 | + return 301 https://www.mysite.com$request_uri; |
| 11 | +} |
| 12 | +# http://www.mysite.com |
| 13 | +server { |
| 14 | + listen 80; |
| 15 | + server_name www.mysite.com; |
| 16 | + |
| 17 | + # HTTPS redirection if the SSL certificate exists |
| 18 | + if (-f /etc/letsencrypt/live/mysite.com/cert.pem) { |
| 19 | + return 301 https://www.mysite.com$request_uri; |
| 20 | + } |
| 21 | + |
| 22 | + # configuration without SSL certificate |
| 23 | + root /home/http/mysite.com/www; |
| 24 | + index index.php index.html; |
| 25 | + # root directory configuration |
| 26 | + location / { |
| 27 | + try_files $uri $uri/ /index.php/$uri; |
| 28 | + } |
| 29 | + # PHP handling with PHP-FPM |
| 30 | + location ~ \.php$ { |
| 31 | + include snippets/fastcgi-php.conf; |
| 32 | + # adjust to your PHP version and socket path |
| 33 | + fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; |
| 34 | + } |
| 35 | + # logs |
| 36 | + error_log /var/log/nginx/www.mysite.com-error.log warn; |
| 37 | + access_log /var/log/nginx/www.mysite.com-access.log combined; |
| 38 | +} |
| 39 | +# https://mysite.com |
| 40 | +server { |
| 41 | + listen 443 ssl http2; |
| 42 | + server_name mysite.com; |
| 43 | + |
| 44 | + # SSL configuration |
| 45 | + ssl_certificate /etc/letsencrypt/live/mysite.com/cert.pem; |
| 46 | + ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; |
| 47 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 48 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 49 | + # redirection |
| 50 | + return 301 https://www.mysite.com$request_uri; |
| 51 | +} |
| 52 | +# https://www.mysite.com |
| 53 | +server { |
| 54 | + listen 443 ssl; |
| 55 | + server_name www.mysite.com; |
| 56 | + |
| 57 | + root /home/http/mysite.com/www; |
| 58 | + index index.php index.html; |
| 59 | + |
| 60 | + # SSL Configuration |
| 61 | + ssl_certificate /etc/letsencrypt/live/mysite.com/cert.pem; |
| 62 | + ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; |
| 63 | + ssl_protocols TLSv1.2 TLSv1.3; |
| 64 | + ssl_ciphers HIGH:!aNULL:!MD5; |
| 65 | + # root directory configuration |
| 66 | + location / { |
| 67 | + try_files $uri $uri/ /index.php/$uri; |
| 68 | + } |
| 69 | + # PHP handling with PHP-FPM (using UNIX socket or network socket) |
| 70 | + location ~ \.php$ { |
| 71 | + # UNIX socket configuration (adjust to your PHP version and socket path) |
| 72 | + include snippets/fastcgi-php.conf; |
| 73 | + fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; |
| 74 | + # network socket configuration (adjust to your PHP-FPM setup as needed) |
| 75 | + #include fastcgi_params; |
| 76 | + #fastcgi_pass 127.0.0.1:9000; |
| 77 | + #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 78 | + } |
| 79 | + # logs |
| 80 | + error_log /var/log/nginx/www.mysite.com-error.log warn; |
| 81 | + access_log /var/log/nginx/www.mysite.com-access.log combined; |
| 82 | +} |
| 83 | + |
0 commit comments