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}';
    	}
    }
    
  • 相关阅读:
    【C语言入门教程】5.6 函数库和文件
    【C语言入门教程】5.5 实现问题(效率)
    【C语言入门教程】5.4 递归
    【C语言入门教程】5.3 函数的调用 与 参数
    【C语言入门教程】5.2 函数的作用域规则(auto, static)
    bootstrap之双日历时间段选择控件示例—daterangepicker(中文汉化版)
    PHP导出数据到CSV文件函数 csv_export()
    MySQL 5.6 Warning: Using a password on the command line interface can be insecure
    【定时任务|开机启动】Windows Server 2008/2012 计划任务配置(任务计划程序)每分钟执行BAT
    【风雪之隅】写在PHP7发布之际一些话 2015-12-02
  • 原文地址:https://www.cnblogs.com/fyblzds/p/12780270.html
Copyright © 2011-2022 走看看