Nginx反代理ASP.NET Core項目


1、將創建的項目dotnet publish進行發布

 

2、運行此網站 dotnet demo.dll

 

 

 

 3、配置nginx

(1) 打開 etc/nginx/nginx.conf配置文件,listen監聽端口,include引用 default.d、conf.d目錄下所有以.conf結尾的配置文件

 
         

 include /etc/nginx/conf.d/*.conf;

server {
        listen       8000 default_server;
        listen       [::]:8000 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

         error_page 404 /404.html;
            location = /40x.html {
        }

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

(2) 進入conf.d目錄下進行自定義添加配置文件

server {
    listen 8001;

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    # error_page 404 /404.html;
    #   location = /40x.html {
    # }

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

(3) 自定義配置文件已創建完成,監聽8001端口,proxy_pass 代理.Net Core Web 5000項目,然后進行檢查與重載配置

nginx -t
nginx -s reload

4、運行調試

接下來在瀏覽器中打開項目

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM