nginx root 和alias

root:


192.168.137.1 - - [23/Jun/2020:09:40:07 +0800] "GET /index.html HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/var/www/html/index.html"

192.168.137.1 - - [23/Jun/2020:09:44:27 +0800] "GET /index.html HTTP/1.1" 200 8 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/var/www/html/index.html"




server{
        listen       8090;
        server_name  localhost;
        #ssl on;
        #從騰訊雲獲取到的第一個文件的全路徑
        #ssl_certificate /etc/ssl/server.pem;
        #ssl_certificate_key /etc/ssl/server.key;
       location /staic  {
            gzip on;
            alias /var/www/html/;
            index  index.html index.htm;
        }
}


訪問:

http://192.168.137.3:8090/static/

192.168.137.1 - - [23/Jun/2020:09:52:02 +0800] "GET /static/ HTTP/1.1" 200 13 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/var/www/html/static/index.html"


如果改成root呢?

server{
        listen       8090;
        server_name  localhost;
        #ssl on;
        #從騰訊雲獲取到的第一個文件的全路徑
        #ssl_certificate /etc/ssl/server.pem;
        #ssl_certificate_key /etc/ssl/server.key;
       location /staic  {
            gzip on;
            root /var/www/html/;
            index  index.html index.htm;
        }
}

報錯:

192.168.137.1 - - [23/Jun/2020:09:54:27 +0800] "GET /static/ HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" "/usr/local/nginx/html/static/"


192.168.137.1 - - [23/Jun/2020:10:01:27 +0800] "GET /static/ HTTP/1.1" 404 188 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36" "-" 

"/var/www/html/static/static/"


正確;
root:

server{
        listen       8090;
        server_name  localhost;
        #ssl on;
        #從騰訊雲獲取到的第一個文件的全路徑
        #ssl_certificate /etc/ssl/server.pem;
        #ssl_certificate_key /etc/ssl/server.key;
       location /  {
            gzip on;
            root /var/www/html/;
            index  index.html index.htm;
        }
}


alias:
server{
        listen       8090;
        server_name  localhost;
        #ssl on;
        #從騰訊雲獲取到的第一個文件的全路徑
        #ssl_certificate /etc/ssl/server.pem;
        #ssl_certificate_key /etc/ssl/server.key;
       location /staic  {
            gzip on;
            alias /var/www/html/;
            index  index.html index.htm;
        }
}


Connection: keep-alive
Content-Encoding: gzip

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章