Nginx服务跳转和静态资源访问的配置(一)

直接看配置:nginx的主配置文件nginx.conf中可以引入其它的配置文件,在http里面添加include vhost/*.conf;





访问静态资源配置:img.tgm.com.conf:

server { 
listen 124; 
#直接访问img.tgm.com:124的时候,访问的是index中的页面文件;如果这里设置的是off,那么location /中的root目录中如果没有index配置的
#文件,则会报403 forbidden错误;但是可以设置为on,显示目录中的文件列表
autoindex on; 
#配置这个后需要在下面的F:/ftpfile/img中添加这个文件,不然访问img.tgm.com:124的时候会报F:/ftpfile/img forbidden错误
index index.html;
#这个是配置的域名,在host里面;使用这个域名访问124端口,就会直接访问location /中的配置
server_name img.tgm.com; 
access_log F:/ftpfile/log/access.log combined; 
#error_page 404 /404.html; 
if ( $query_string ~* ".*[\;'\<\>].*" ){ 
return 404; 

location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* { 
deny all; 

location / { 
root F:/ftpfile/img; 
add_header Access-Control-Allow-Origin *; 

访问其他服务器:

server { 
listen 124; 
autoindex off; 
#这个是配置的域名,在host里面;使用这个域名访问124端口,就会直接访问location /中的配置
server_name tomcat.tgm.com; 
access_log F:/ftpfile/log/access.log combined; 
index index.html; 
#error_page 404 /404.html; 
if ( $query_string ~* ".*[\;'\<\>].*" ){ 
return 404; 

location / { 
proxy_pass http://127.0.0.1:8080; 
add_header Access-Control-Allow-Origin *; 


猜你喜欢

转载自blog.csdn.net/CristianTang/article/details/80783068