Skip to content

Instantly share code, notes, and snippets.

@charlesrc019
Last active November 8, 2024 02:23
Show Gist options
  • Save charlesrc019/3754806b60e017cfeb45b0f299cf7c38 to your computer and use it in GitHub Desktop.
Save charlesrc019/3754806b60e017cfeb45b0f299cf7c38 to your computer and use it in GitHub Desktop.
server_config_dual_http_and_https.nginx
# Default
server {
server_name dev1.simplifize.co;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# process PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock; # php-fpm
# fastcgi_pass 127.0.0.1:9000; # php-cgi
}
# deny access to .htaccess
location ~ /\.ht {
deny all;
}
# SSL
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/dev1.simplifize.co/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dev1.simplifize.co/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
# Virtual
server {
# force redirect to HTTPS if via hostname
if ($host = dev1.simplifize.co) {
return 301 https://$host$request_uri;
}
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# process PHP
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock; # php-fpm
# fastcgi_pass 127.0.0.1:9000; # php-cgi
}
# deny access to .htaccess
location ~ /\.ht {
deny all;
}
listen 80;
listen [::]:80;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment