Home  >  Article  >  Backend Development  >  Can't access localhost?

Can't access localhost?

WBOY
WBOYOriginal
2016-08-18 09:15:381838browse

I am using the local ubuntu nginx as the web server. However, it has been working fine some time ago, but suddenly I can't connect to localhost. I checked a lot of information but can't find a solution.
nginx service is on as follows:

<code>$ sudo service nginx status
 * nginx is running</code>

/etc/nginx/nginx.conf is untouched by default, and the include is also correct, as follows:

<code>##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;</code>
The default in

/etc/nginx/site-available is as follows:

<code>server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        # kfastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

}
</code>

Then access localhost as follows:

Can't access localhost?

How to solve it


127.0.0.1 is also inaccessible and no proxy is enabled.

Reply content:

I am using the local ubuntu nginx as the web server. However, it has been working fine some time ago, but suddenly I can't connect to localhost. I checked a lot of information but can't find a solution.
nginx service is on as follows:

<code>$ sudo service nginx status
 * nginx is running</code>

/etc/nginx/nginx.conf is untouched by default, and the include is also correct, as follows:

<code>##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;</code>
The default in

/etc/nginx/site-available is as follows:

<code>server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        # kfastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one

}
</code>

Then access localhost as follows:

Can't access localhost?

How to solve it


127.0.0.1 is also inaccessible and no proxy is enabled.

The architecture of

Nginx under ubuntu is different from centos or windows. Usually all site configurations of nginx are placed in the /etc/nginx/site-availabl directory, but please note that this It is just the available configuration. If you want to enable the configuration of a motile site such as (www.test.com), you need to create a soft connection in /etc/nginx/site-enabled

<code class="bash">$ pwd
/etc/nginx/site-enabled

$ sudo ln -s /etc/nginx/site-availabl/www.test.com www.test.com</code>

After the soft connection is created, ChongqingNG,

<code>$ cat /etc/hosts 
</code>

Check if there is 127.0.0.1 locahost
If not

<code># echo "127.0.0.1 locahost" >> /etc/hosts
</code>

Solved it, but I don’t quite understand it;
I copied a copy of the default file in site-available to /etc/nginx/conf.d/default.conf
and then

<code>sudo nginx -t
sudo service nginx restart</code>

That’s it. Doesn’t it mean that /etc/nginx/conf.d and /etc/nginx/site-available can be written in any of their directories?

Is it a firewall setting problem?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn