ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

利用nginx解决Nuget无法访问的问题

2021-11-08 13:32:08  阅读:286  来源: 互联网

标签:nuget ## 无法访问 server Nuget nginx gzip cdn


利用nginx解决Nuget无法访问的问题

通过nginx的代理能力,实现以下两个功能:

  1. 将api.nuget.org指向国内镜像源nuget.cdn.azure.cn。
  2. 将代理响应的nuget.cdn.azure.cn/v3/index.json中的文本“api.nuget.org”自动替换为:“nuget.cdn.azure.cn”。

操作环境:deepin 20.4

1. 安装nginx

$sudo apt install nginx-full

2. 配置nginx

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip off;

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
	
	##
	# Virtual Host Configs
	##
	server {
		listen		80;		
		server_name 	localhost;		
		#charset utf-8;		
		#location /forward {			
		#	rewrite	/forward/(.*)$ /$1 break;
		#	proxy_pass	https://nuget.cdn.azure.cn/;				
		#}
		
		location / {			
			#proxy_pass	http://127.0.0.1/forward;	
			proxy_pass	https://nuget.cdn.azure.cn/;	
			#proxy_set_header	Accept-Encoding "";	
			
			sub_filter_types	*;
			sub_filter_once	off;	
			sub_filter	'api.nuget.org' 'nuget.cdn.azure.cn';			
		}		
	}

	include /etc/nginx/conf.d/*.conf;
	#include /etc/nginx/sites-enabled/*;
}

3. 配置nuget源

#查看源列表
$ dotnet nuget list source

#添加源
$ dotnet nuget add source http://127.0.0.1/v3/index.json -n nuget.nginx

#禁用原有默认源
$ dotnet nuget disable source nuget.org

如果国内源今后采用了gzip压缩响应,可以参考:【解决 sub_filter 不能替换 Gzip 过的内容】的方法解决,上面的配置文件server{}中注释掉的部分已实现相关配置,可自行实验。

标签:nuget,##,无法访问,server,Nuget,nginx,gzip,cdn
来源: https://blog.csdn.net/yr7942793/article/details/121205498

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有