zoukankan      html  css  js  c++  java
  • Nginx配置静态文件问题

    此为容器访问宿主机tomcat例子

    出现问题:通过nginx访问tomcat时无图形界面

    我们访问http://IP:端口/***.png(nginx的访问链接),但是实际访问的静态文件是的容器中的路径:

     所以我们应该把宿主机的目录挂载到容器,或者直接拷贝文件到容器内,然后给路径

    -v /px/nginx/webapps:/webapps/ROOT

    发现nginx访问tomcat时候只能访问首页,点击别的会报404

    解决:

    在nginx.conf配置里面的server位置下加入如下内容即可:

    location ~ .* {
                proxy_pass  http://tomcatserver;  #http://你的upstream配置的名称;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Fonwarded-For $proxy_add_x_forwarded_for;
            }

    以下为nginx.conf文件,在docker内为default.conf文件内容(参考)

    upstream tomcatserver{
        server 192.168.10.197:8087 weight=1;
            server 192.168.10.197:8089 weight=2;
        }

    server {

        listen       80;
        server_name  localhost;

        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;

        #location / {
         #   root   /usr/share/nginx/html;
          #  index  index.html index.htm;
       # }
        location ~ .jsp$ {
            proxy_pass http://tomcatserver;
         }

           location ~ .(html|js|css|png|gif|ico|jpg)$ {
                root /webapps/ROOT;
            }


        #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   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }

  • 相关阅读:
    CORS跨域解决方案
    修改数据库排序规则实践总结
    【转】通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core?
    调用远程数据库的T-SQL和SP(SQLSERVER)
    解决在微信网页中百度地图定位不准确的问题
    VUE小知识点
    实现鼠标移过时,显示图片的功能
    实现导出功能
    两数据库表之间迁移插入数据
    IIS配置FTP
  • 原文地址:https://www.cnblogs.com/Px-Passion/p/13529847.html
Copyright © 2011-2022 走看看