{"id":531,"date":"2016-10-01T16:22:52","date_gmt":"2016-10-01T08:22:52","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=531"},"modified":"2018-09-04T23:54:15","modified_gmt":"2018-09-04T15:54:15","slug":"the-nginx-configurations-that-i-had-created-to-serve-only-robots-txt-and-sitemap-index-xml-over-http","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/the-nginx-configurations-that-i-had-created-to-serve-only-robots-txt-and-sitemap-index-xml-over-http\/","title":{"rendered":"The Nginx configurations that I had created to serve only robots.txt and sitemap-index.xml over http"},"content":{"rendered":"<p>I had initially configured a set of Nginx rules that will redirect every single request made over http to https. However, that breaks my doing so breaks my reference on <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-send-http-get-request-with-java-without-using-any-external-libraries\/\" title=\"How to send HTTP GET request with Java without using any external libraries\" target=\"_blank\">how to send HTTP GET request with Java without using any external libraries<\/a>. <\/p>\n<p>Since the robots.txt is not sensitive data, I had decided to allow it to be retrieved via http as well. And since my robots.txt points to <code>sitemap-index.xml<\/code> via http, I also allowed <code>sitemap-index.xml<\/code> to be retrieved via http as well. <\/p>\n<p>This post documents the changes that I had made to my Nginx configurations to serve only <code>robots.txt<\/code> and <code>sitemap-index.xml<\/code> over the http protocol.<\/p>\n<h2>The Nginx configurations that redirects all http traffic to https<\/h2>\n<p>My initial Nginx configurations for redirecting all http traffic to https was as follows:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nserver {\r\n\r\n    listen 80;\r\n    server_name   techcoil.com www.techcoil.com;\r\n    return 301 https:\/\/www.techcoil.com$request_uri;    \r\n\r\n}\r\n<\/pre>\n<p>What this set of code does is straightforward; it tells Nginx to return a response with the <strong>301 Moved Permanently<\/strong> status code whenever there are HTTP requests received from port 80 which are directed at the domains <code>techcoil.com<\/code> or <code>www.techcoil.com<\/code>.<\/p>\n<h2>The resultant Nginx rules for allowing HTTP accesses to only robots.txt and sitemap-index.xml<\/h2>\n<p>The resultant Nginx rules for allowing HTTP accesses to only robots.txt and sitemap-index.xml is as follows:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nserver {\r\n\r\n        listen 80;\r\n        server_name   techcoil.com www.techcoil.com;\r\n        root    \/path\/to\/directory\/that\/contains\/robot.txt\/and\/sitemap-index.xml;\r\n\r\n        location \/robots.txt {\r\n\r\n        }\r\n\r\n        location \/sitemap-index.xml {\r\n\r\n        }\r\n\r\n        location \/ {\r\n                return 301 https:\/\/www.techcoil.com$request_uri;\r\n        }\r\n}\r\n<\/pre>\n<p>I included the <code>root<\/code> command that will point Nginx to read files from the directory that contains <code>robots.txt<\/code> and <code>sitemap-index.xml<\/code>. <\/p>\n<p>I then added 3 new location blocks:<\/p>\n<ul>\n<li>The <code>location \/robots.txt<\/code> block detects HTTP requests directed at <code>http:\/\/techcoil.com\/robots.txt<\/code> or <code>http:\/\/www.techcoil.com\/robots.txt<\/code>.<\/li>\n<li>The <code>location \/sitemap-index.xml<\/code> block detects HTTP requests directed at <code>http:\/\/techcoil.com\/sitemap-index.xml<\/code> or <code>http:\/\/www.techcoil.com\/sitemap-index.xml<\/code>.<\/li>\n<li>The <code>location \/<\/code> block detects all other HTTP requests and return a response with the <strong>301 Moved Permanently<\/strong> status code to tell the browser to change the access protocol to https.<\/li>\n<\/ul>\n<p>For my Nginx server, the empty lines between the braces of the first two blocks are necessary to make Nginx return <code>robots.txt<\/code> and <code>sitemap-index.xml<\/code>.  <\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-8z\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-8z&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-8z&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F531&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>I had initially configured a set of Nginx rules that will redirect every single request made over http to https. However, that breaks my doing so breaks my reference on <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-send-http-get-request-with-java-without-using-any-external-libraries\/\" title=\"How to send HTTP GET request with Java without using any external libraries\" target=\"_blank\">how to send HTTP GET request with Java without using any external libraries<\/a>. <\/p>\n<p>Since the robots.txt is not sensitive data, I had decided to allow it to be retrieved via http as well. And since my robots.txt points to <code>sitemap-index.xml<\/code> via http, I also allowed <code>sitemap-index.xml<\/code> to be retrieved via http as well. <\/p>\n<p>This post documents the changes that I had made to my Nginx configurations to serve only <code>robots.txt<\/code> and <code>sitemap-index.xml<\/code> over the http protocol.<\/p>\n","protected":false},"author":1,"featured_media":1240,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[225,318,319,195,57],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Nginx-Logo.jpg","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-8z","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/531"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=531"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1240"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}