浏览器访问“/”或者“/digi-”走静态文件,其余的走本地服务的nginx配置示例

# 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;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值