nginx 已有80端口服务如何在开启一个非80端口的静态资源指向

 要求是这样的 当前以及有一个80端口 http服务的的动态server A  然后A服务也有也有静态资源的指向 

如果这个时候在这这个nginx做一个新的非80服务的纯静态资源包的指向  如何做?

 

1 首先给出一个 例子 针对的不是上面描述的需求 就是已经有一个非80端口的静态资源指向 ,再给出另外一个别的非80端口的静态资源的指向

 

 

server {
	listen 7080 default_server;
	#listen [::]:80 default_server ipv6only=on;

	add_header Access-Control-Allow-Origin '*' ; #X-UA-Compatible 'IE=Edge,chrome=1'
	
	error_page 400 403 404 /error_pages/404.html;
	root /usr/share/nginx/html;
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name localhost;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}
	
	location ~ ^/nginx_status/ {
	    stub_status on;
	    access_log off; 
	}
	

server {
	listen 9810 default_server;
	#listen [::]:80 default_server ipv6only=on;

	error_page 400 403 404 /error_pages/404.html;
	root /Revit;
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name localhost;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
		# Uncomment to enable naxsi on this location
		# include /etc/nginx/naxsi.rules
	}
}


server {
	listen 9991 default_server;
	#listen [::]:80 default_server ipv6only=on;

	error_page 400 403 404 /error_pages/404.html;
	root /var/www/html;
	index index.html index.htm;

	# Make site accessible from http://localhost/
	server_name localhost;

	# location ~ /seaf {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
	# 	try_files $uri $uri/ =404;
		# Uncomment to enable naxsi on this location<pre name="code" class="html"><span style="font-family: Arial, Helvetica, sans-serif;">		# include /etc/nginx/naxsi.rules</span>

# }}

 

 

 

 

 

上例中就是7080端口做一个静态指向,然后9991 也是一个新的静态资源指向 root指向对应的静态资源

 

 

2  下面给出本文开始说的那种情况的一个解决思路

当前已经有针对80服务的端口 的nginx的代理服务,如果再加一个静态资源包的指向

使用上面添加9991端口的方法就不行了 测试发现 会被80端口服务拦截

经过尝试发现一个折中的办法 

在80代理的server 首先指向静态资源包的文件夹名字  所有带有该文件夹名字的url 会被拦截 然后就不走后面的80的端口代理了

如下

 

 


 

 

 

 

 

 

 

server {
    listen       80 default;
    server_name  _;
	index index.html index.htm index.jsp;
	root html;
		
	location ^~ /xxxxxxfmTemp/ {
            root /nodejs/;   ##会指向/home/admin/www  
            autoindex on;       ##会自动显示资源目录  
          # index noindex.htm;        
         }
	

	location ~ /XXXXXapp
	{
		proxy_pass    http://127.0.0.1:8080;
	}
	
	

	location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
	{
		
		expires 30d;
	}

	location ~ .*\.(js|css)?$
	{
 		
		expires 1h;
	}

	access_log  /usr/local/nginx/logs/access.log;
}

 

 

 

 

 

静态资源的调用 

http://120.xxx.xxx.231/xxxxxxfmTemp/admin/zjzx_index.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值