Nginx将目录作为别名提供服务

前端之家收集整理的这篇文章主要介绍了Nginx将目录作为别名提供服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图使用ResourceSpace作为Nginx的别名.页面脚本加载良好,但不加载静态文件.访问子目录会产生未定义索引的错误

eximmanger加载所有脚本和静态文件,而资源空间无法加载静态文件,只加载脚本

这是我的配置

server {
    listen 80;
    server_name myserver.com www.myserver.com;
    server_name_in_redirect off;

    access_log /var/log/Nginx/myserver.access_log main;
    error_log /var/log/Nginx/myserver.error_log info;

    location /resourcespace { 
        alias /var/www/html/ResourceSpace/;

     }


    location /eximmanager { 
        alias /var/www/html/exim4u/exim4u/;

     }

    location /100/ { 
           rewrite ^ http://100.myserver permanent;

     }




   location ~ ^/eximmanger/(.+\.*)${
      alias /var/www/html/exim4u/exim4u/$1;
      fastcgi_pass unix:/tmp/PHP.socket;
      fastcgi_index index.PHP;
      fastcgi_param SCRIPT_FILENAME  $request_filename;

      # From fastcgi_params
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      /var/www/html/exim4u/exim4u; # <-- Changed
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    Nginx/$Nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param  REDIRECT_STATUS    200;
    }


   location ~ ^/resourcespace/(.+\.*)${
      alias /var/www/html/ResourceSpace/$1;
      fastcgi_pass unix:/tmp/PHP.socket;
      fastcgi_index index.PHP;
      fastcgi_param SCRIPT_FILENAME  $request_filename;

      # From fastcgi_params
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      /var/www/html/ResourceSpace; # <-- Changed
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    Nginx/$Nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param  REDIRECT_STATUS    200;
    }


    root /var/www/html/myserver;
    index index.PHP;
    # Support Clean (aka Search Engine Friendly) URLs
    location / {
            try_files $uri $uri/ /index.PHP?q=$request_uri;
    }

    index index.PHP index.html index.htm default.html default.htm;
    # deny running scripts inside writable directories
    location ~* /(images|cache|media|logs|tmp)/.*\.(PHP|pl|py|jsp|asp|sh|cgi)${
            return 403;
            error_page 403 /403_error.html;
    }



    location ~ .*.PHP${
        #include /etc/Nginx/fastcgi_params;
        fastcgi_pass unix:/tmp/PHP.socket;
        fastcgi_index index.PHP;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


    }

    # caching of files 
    location ~* \.(ico|pdf|flv)${
            expires 1y;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)${
            expires 14d;
最佳答案
我发现问题根本与Nginx无关,而是与ResourceSpace $baseurl指令有关.在指令中,我混淆了$baseurl =’http://resourcespace.myserver.com’;和$baseurl =’http://myserver.com/resourcespace’; .如果你有类似的问题,请注意这一点.
原文链接:https://www.f2er.com/nginx/434464.html

猜你在找的Nginx相关文章