简体   繁体   中英

nginx returns blank page

i have a php api running in docker, i want to setup a reverse proxy using nginx on my host. currently, when i visit mydomain.com/doc i get a blank screen but if i try with my server's ip address 111.111.11:8000/doc it works fine. Also, if i use mydomain.com:8000/doc it also works fine. i would like to access it via mydomain.com/doc. my nginx config:

server {
    listen 81 default_server;
    server_name mydomain.com;

    

        location /doc {
                proxy_pass         http://0.0.0.0:8000/doc;
                error_log /var/log/nginx/php-error.log info;
                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;
                proxy_set_header   X-Forwarded-Host $server_name;

        }

}

i want my domain accessible via domain.com/doc

I see a misunderstanding with with the 0.0.0.0 ip

0.0.0.0 is only usable for listing because it means "listen to all IPv4", in contrast to 127.0.0.1 which means "only listen to 127.0.0.1". But you can not use it to connect to something, it is not a routable IP.

Example nginx config with the IP issue fixed. I have also removed the doc parts, it is redundant and only needed if you really depend on an extra location block:

server {
    listen 80 default_server;
    server_name mydomain.com;

    location / {
        proxy_pass http://127.0.0.1:8000/;
        error_log /var/log/nginx/php-error.log info;
        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;
        proxy_set_header X-Forwarded-Host $server_name;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM