nginx 已有80端口服务如何在开启一个非80端口的静态资源指向
2016-10-14 11:12
405 查看
要求是这样的 当前以及有一个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
如果这个时候在这这个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
相关文章推荐
- 如何在已有网站的服务器上面,通过nginx配置虚拟主机来达到多个应用使用同一个服务器的效果
- 如何构建一个完整的angular项目(一)--- 如何按需加载静态资源
- 如何开启nginx 的https服务
- 二.Nginx反向代理和静态资源服务配置
- CentOS6.7使用nginx提供静态资源服务,反向代理和负载均衡
- Nginx作为静态资源web服务之防盗链
- 如何让aspnet服务加载静态资源html(我的动态网页静态化) 转
- Nginx作为静态资源web服务之缓存原理
- Nginx作为静态资源web服务之跨域访问
- 阿里云服务器nginx下如何添加伪静态以及配置静态资源地址
- 云服务通过nginx访问静态资源
- 如何使用nginx,在同一个tompcat下面部署多个服务
- nginx的静态资源服务
- Nginx静态资源服务器开启https配置及http rewrite到https
- nginx开启gzip加速你的静态资源加载
- 如何开启nginx 的https服务
- 一个Socket服务的例子! 请高手指点无法捕捉的输出如何修改?
- 一个Socket服务的例子! 请高手指点无法捕捉的输出如何修改?
- 如何查看某一个进城池占用cou资源比较大?