WebEnh

.net7 mvc jquery bootstrap json 学习中 第一次学PHP,正在研究中。自学进行时... ... 我的博客 https://enhweb.github.io/ 不错的皮肤:darkgreentrip,iMetro_HD
随笔 - 1079, 文章 - 1, 评论 - 75, 阅读 - 174万
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1、实现转发

打开conf下的nginx.conf文件,如下图:

 

2、添加.net core网站的转发

按下面的进行修改,修改完后,就把localhost的80转发到了https://localhost:5004的.net core应用上了。

复制代码
复制代码
    server {
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass https://localhost:5004;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
复制代码
复制代码

 

3、同一个端口下添加多个.net core应用

设置完后,就可以通过 localhost:83 访问 https://localhost:5004的网站,通过localhost:83/api 访问https://localhost:44378的网站

复制代码
复制代码
    server {
        listen       83;
        server_name  localhost;
        
        location / {
            proxy_pass https://localhost:5004;
        }
        
        location ^~/api/ {
            proxy_pass https://localhost:44378/;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
复制代码
复制代码

 注意二级目录转的时候,子目录后面要有斜扛,转发的那个地址后面也要有斜扛,如下:

     location /data/ {
            proxy_pass https://localhost:5006/;
        }

 

4、同一个端口,多个域名的支持

复制代码
复制代码
    server {
        listen       80;
        server_name  www.aaa.com;
        
        location / {
        proxy_pass http://localhost:8081;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       80;
        server_name  www.bbb.com;
        
        location / {
        proxy_pass http://localhost:8082;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
复制代码
复制代码

 5、实现https支持

复制代码
复制代码
    server {
        listen       443 ssl;
        server_name  localhost;

    ssl_certificate ..\ssl\5859212_www.aaa.com.pem;

    ssl_certificate_key ..\ssl\5859212_www.aaa.com.key;

    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_prefer_server_ciphers on;

        location / {
        proxy_pass http://localhost:8081;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
复制代码
复制代码

 如果想实现http自动跳转到https,可以再加一个server,如下:

    server {
    listen 80;
    server_name  localhost;
    rewrite ^(.*) https://$server_name$1 permanent;
    }

  6、在IdentityServer4中的使用

 如果想在identityserver4里使用必须加上下面的逻辑

复制代码
复制代码
     location / {
            proxy_pass https://localhost:5005;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect off;
            proxy_buffering off;
            expires           0;
        }
复制代码
复制代码

 

 

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2019-12-22 测试开源.net 混淆器ConfuserEx
2019-12-22 nginx 目录自动加斜线”/”
2017-12-22 Asp.net 与 UCenter 用户同步之实施过程
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

了解更多