# HTTP Server: Redirect all HTTP traffic to HTTPS
server {
listen 80;
server_name www.demo.com;
location / {
return 301 https://www.demo.com$request_uri;
}
}
# HTTPS Server: Serve static files and proxy other requests
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.demo.com;
# SSL configuration managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.demo.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.demo.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
access_log /app/cms/wordpress/www.demo.com_nginx.log combined;
index index.html index.htm index.php;
# Serve static files at the root path
location = / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
# Serve static files for paths starting with /digi-
location ^~ /digi- {
root /usr/share/nginx/html;
try_files $uri $uri/ =404;
}
# Proxy all other requests to the backend service
location / {
try_files $uri $uri/ @backend;
}
# Backend proxy configuration
location @backend {
proxy_pass http://127.0.0.1:5480;
proxy_set_header Host $host;
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;
}
# Specific proxy configuration for /WebHook
location /WebHook {
proxy_pass http://localhost:5000/WebHook;
proxy_set_header Host $host;
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;
}
}
浏览器访问“/”或者“/digi-”走静态文件,其余的走本地服务的nginx配置示例
最新推荐文章于 2024-10-13 15:11:00 发布