zoukankan      html  css  js  c++  java
  • Nginx 直接输出IP地址,免端口

    server {
    	listen 80;
    	listen [::]:80 ipv6only=on;
    	server_name ip.larva.com.cn;
    
    	location / {
    		if ($request_method !~* GET|OPTIONS) {
    			return 403;
    		}
    		if ($request_method = 'OPTIONS') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			#
    			# Custom headers and headers various browsers *should* be OK with but aren't
    			#
    
    			add_header 'Access-Control-Allow-Headers' '*';
    			#
    			# Tell client that this pre-flight info is valid for 20 days
    			#
    
    			add_header 'Access-Control-Max-Age' 1728000;
    			add_header 'Content-Type' 'text/plain; charset=utf-8';
    			add_header 'Content-Length' 0;
    			return 204;
    		}
    		if ($request_method = 'GET') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			add_header 'Access-Control-Allow-Headers' '*';
    			add_header 'Access-Control-Expose-Headers' '*';
    			add_header 'Content-Type' 'text/plain; charset=utf-8';
    		}
    
    		return 200 $remote_addr;
    	}
    
    	location /port {
    		if ($request_method !~* GET|OPTIONS) {
    			return 403;
    		}
    		if ($request_method = 'OPTIONS') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			#
    			# Custom headers and headers various browsers *should* be OK with but aren't
    			#
    
    			add_header 'Access-Control-Allow-Headers' '*';
    			#
    			# Tell client that this pre-flight info is valid for 20 days
    			#
    
    			add_header 'Access-Control-Max-Age' 1728000;
    			add_header 'Content-Type' 'text/plain; charset=utf-8';
    			add_header 'Content-Length' 0;
    			return 204;
    		}
    		if ($request_method = 'GET') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			add_header 'Access-Control-Allow-Headers' '*';
    			add_header 'Access-Control-Expose-Headers' '*';
    			add_header 'Content-Type' 'text/plain; charset=utf-8';
    		}
    
    		return 200 '$remote_addr:$remote_port';
    	}
    
    	location /json {
    		if ($request_method !~* GET|OPTIONS) {
    			return 403;
    		}
    		if ($request_method = 'OPTIONS') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			#
    			# Custom headers and headers various browsers *should* be OK with but aren't
    			#
    
    			add_header 'Access-Control-Allow-Headers' '*';
    			#
    			# Tell client that this pre-flight info is valid for 20 days
    			#
    
    			add_header 'Access-Control-Max-Age' 1728000;
    			add_header 'Content-Type' 'text/plain; charset=utf-8';
    			add_header 'Content-Length' 0;
    			return 204;
    		}
    		if ($request_method = 'GET') {
    			add_header 'Access-Control-Allow-Origin' '*';
    			add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
    			add_header 'Access-Control-Allow-Headers' '*';
    			add_header 'Access-Control-Expose-Headers' '*';
    			add_header 'Content-Type' 'application/json; charset=utf-8';
    		}
    
    		return 200 '{"ip":"$remote_addr","port":$remote_port}';
    	}
    }
    
  • 相关阅读:
    NIO与普通IO文件读写性能对比
    JAVA学习.java.sql.date 与java.util.date以及gettime()方法的分析
    软件工程之软件设计
    ubuntu下管理android手机
    AFNetworking2.0 NSHipster翻译
    【Jsoup爬取网页内容】
    IOS 表视图UITableView 束NSBundle
    如何将位图格式图片文件(.bmp)生成geotiff格式图片?
    opencv3 使用glob遍历并修改文件名
    Ubuntu clion下载及激活
  • 原文地址:https://www.cnblogs.com/fyblzds/p/12780270.html
Copyright © 2011-2022 走看看