1

When I go to localhost on my pc, I can connect, but when I go to my router's public ip on the host pc, the page gets timed out. It works on my phone and I am able to see the website.

Here is my nginx configuration: (I've replaced the listen address with ***):

server {
                listen 80;
                server_name ***;
                index index.html index.php;
            access_log /var/log/nginx/localhost.access_log main;
            error_log /var/log/nginx/localhost.error_log info;

            root /var/www/localhost/htdocs;
            location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
            }

            listen 443 ssl; # managed by Certbot
            ssl_certificate /etc/letsencrypt/live/***/fullchain.pem; # managed by Certbot
            ssl_certificate_key /etc/letsencrypt/live/***/privkey.pem; # managed by Certbot
            include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
            ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
            if ($scheme != "https") {
                return 301 https://$host$request_uri;
            } # managed by Certbot
            #return 404; # managed by Certbot

}

1 Answers1

0

There is some information missing to be sure what solves you problem.

My guess is that you need the set the "default server" to get something from localhost. The servername option tells nginx to only listen for requests going to the configured IP-Name. Usually localhost is not accessed by the servername.

listen      80 default_server;

From nginx manual (http://nginx.org/en/docs/http/request_processing.html):

In this configuration nginx tests only the request’s header field “Host” to determine which server the request should be routed to. If its value does not match any server name, or the request does not contain this header field at all, then nginx will route the request to the default server for this port.

Marco
  • 406