This article is a mirror article of machine translation, please click here to jump to the original article.

View: 20313|Reply: 3

[Web] nginx returns the specified content when visiting the specified page

[Copy link]
Posted on 8/18/2017 10:00:43 AM | | | |
Here's the thing, yesterday the website was upgraded from http to https protocol

One of my software interfaces to access this website, such as:http://www.itsvse.com/api/test.php

If you access it directly with your browser, you will be automatically redirected to  https://www.itsvse.com/api/test.php


However, my software code does not write code for automatic redirection, that is, the address where the software accesses my interface


will return a 301 status code, and the nginx default 301 error page,


In this way, the software cannot read the data from the interface, but I cannot change https back to the original http


Can nginx determine when you visit a specified page and return the specified content???


The answer is yes!!!!

This code is placed in the server, as far as possible

When we visit the /api/test.php page, nginx automatically returns a json string to the client, and the test result is as follows:

(default_type and add_header will get an error when added to it, I don't know why, but it doesn't affect haha)






Previous:Very easy to use transcoding tool [GBK-UTF8 interchange]
Next:Sort strings a10, a2, a3, a6, a5, a4
 Landlord| Posted on 8/18/2017 10:03:50 AM |
Fixed JSON:



 Landlord| Posted on 8/18/2017 10:05:45 AM |
nginx json format output

log_format logstash_json '{ "@timestamp": "$time_local", '
                         '"@fields": { '
                         '"remote_addr": "$remote_addr", '
                         '"remote_user": "$remote_user", '
                         '"body_bytes_sent": "$body_bytes_sent", '
                         '"request_time": "$request_time", '
                         '"status": "$status", '
                         '"request": "$request", '
                         '"request_method": "$request_method", '
                         '"http_referrer": "$http_referer", '
                         '"body_bytes_sent":"$body_bytes_sent", '
                         '"http_x_forwarded_for": "$http_x_forwarded_for", '
                         '"http_user_agent": "$http_user_agent" } }';



Specifying the log format:


access_log  /data/logs/nginx/www_itsvse_com.access.log  logstash_json;


input {
    file {
        path => "/var/log/nginx/access.log_json""
        codec => "json"
    }
}

Posted on 8/18/2017 10:40:03 AM |
If you really can do it, I will admire you
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com