docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > Nginx docker部署访问403

Nginx docker容器版部署访问403的解决

作者:缘友一世

本文主要介绍了Nginx docker容器版部署访问403的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

问题记录

1.194.128.78 - - [04/Dec/2023:11:12:39 +0000] "GET /api/product/getBaseCategoryList HTTP/1.1" 403 
238 "http://47.92.131.235/home" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36 Edg/119.0.0.0"

解决结果

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;


include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    server {
        listen       80;
        server_name  _;
        # include /etc/nginx/default.d/*.conf;

	    location / {
		    root   #本地vue项目地址;
            try_files $uri $uri/ /index.html;
            index  index.html;
    	}
	    location /api {
            proxy_pass 远程主机地址; #http://xxx.xxx.xxx.xxx
	    }
        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }


server {
        listen       8080;
        server_name  localhost;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        location / {
            root   #本地vue项目地址;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
		# 监听的请求location 请根据时机项目内容进行配置
        location /dev-api/ {
            proxy_pass 远程主机地址; #http://xxx.xxx.xxx.xxx
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
            rewrite ^/dev-api/(.*)$ /$1 break;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

到此这篇关于Nginx docker容器版部署访问403的解决的文章就介绍到这了,更多相关Nginx docker部署访问403内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

您可能感兴趣的文章:
阅读全文