`
wj98127
  • 浏览: 264112 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

nginx多项目和图片服务器配置

 
阅读更多

nginx下多项目部署,根据路径进行区分,修改配置文件如下:

 

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        location / {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            index  index.jsp index.html;
            proxy_pass http://localhost:8088;
        }
        access_log  logs/host.access.log;

        location /crra {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            index  index.jsp index.html;
            proxy_pass http://localhost:9080/crra;
        }
        ##image server配置
        location /images/ {
           alias /home/images/;
           autoindex on;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

 

 

以上图片服务器的配置部分,也可以写成:

location /images/ {
      root /home/images/;
      autoindex on;
}

 

root和alias的区别在于,root的访问路径是http://ip/home/images/images/top.gif,alias的请求路径是http://ip/images/top.gif请求。

root响应的路径:配置的路径+完整访问路径(完整的location配置路径+静态文件)

alias响应的路径:配置路径+静态文件(去除location中配置的路径)

 

使用alias时目录名后面一定要加“/”;

在location /中配置root,在location /other中配置alias;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics