Nginx簡單部署靜態頁面


環境:CentOS 7

Nginx根目錄:/etc/nginx/

  1. 在Nginx根目錄下創建一個目錄(文件夾),命名為:html。用於放置頁面文件。
  2. 編輯/etc/nginx/conf.d下的default.conf(因為主配置文件/etc/nginx/nginx.conf包含了/etc/nginx/conf.d/default.conf
  3. /etc/nginx/nginx.conf內容修改如下(刪除掉了默認的注釋內容,先從基礎搞起,一點點深入了解配置)
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html; # 指定根目錄下的靜態文件目錄(相對)
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # 設置反向代理
        location /v/ {
                proxy_pass  http://xxx.com/api/;
        }
    }
    
  4. 以上修改了默認端口的訪問內容。然后局域網訪問(內容包含了一些ajax反向代理請求的內容):
  5. index.html內容如下:
    <!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>
    

     

(*^__^*) ,粗略記錄,后期慢慢記錄補充~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM