Nginx simple static page deployment

Environment: CentOS 7

Nginx root directory: / etc / nginx /

  1. Create a directory (folder) in the Nginx root directory named: HTML. For placing the page file.
  2. Edit /etc/nginx/conf.d under default.conf ( because the main configuration file /etc/nginx/nginx.conf contains /etc/nginx/conf.d/ default.conf )
  3. The /etc/nginx/nginx.conf content is modified as follows (deleted the default annotation content, starting with the foundation huh, a little bit of insight into configuration) :
    {Server 
        the listen 80; 
        server_name localhost; 
        LOCATION / { 
            the root HTML; # specify static file directory under the root directory (relative) 
            index index.html index.htm; 
        } 
        error_page 500 502 503 504 /50x.html; 
        LOCATION = / 50X. {HTML 
            the root / usr / Share / Nginx / HTML; 
        } 
       # set reverse proxy 
        LOCATION / V / { 
                proxy_pass http://xxx.com/api/; 
        } 
    }
    
  4. Above modify the default port to access the content. Then LAN Access (content contains some content ajax reverse proxy request):
  5. index.html reads as follows:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>My nginx server</title>
    </head>
    <body>
    <h3 style="text-align: center">^(* ̄(oo) ̄)^</h3>
    <div id="json"></div>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>
    <script type="text/javascript">
        function textAjax() {
            axios.post('/v/test/get', {mode:'test'})
                .then(function (response) {
                    console.log(response);
                    $('#json').html(JSON.stringify(response))
                })
                .catch(function (error) {
                    console.log(error);
                });
        }
        $(function () {
            textAjax();
        });
    </script>
    </body>
    </html>
    

     

(* ^ __ ^ *), a rough record, post-record slowly replenish ~

Guess you like

Origin www.cnblogs.com/gme5/p/11727680.html