• 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
    
    
  • 相关阅读:
    3 * 0.1 == 0.3 将会返回什么?true 还是 false?
    Java中存储金额用什么数据类型?
    oracle数据库中索引失效的几种情况
    MyBatis如何防止SQL注入
    Windows10连接到内网(局域网)段
    Linux上安装Tomcat并启动时报Cannot find /usr/local/tomcat/tomcat_8080/bin/setclasspath.sh
    Linux上安装Mysql
    Linux上安装JDK
    FileZilla的使用和注意事项
    Failure to find parent:pom:2.2.6 in http://maven.aliyun was cached in the local repository...
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348311.html
Copyright © 2020-2023  润新知