Home > Backend Development > PHP Tutorial > Can't access localhost?

Can't access localhost?

WBOY
Release: 2016-08-18 09:15:38
Original
1858 people have browsed it

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>
Copy after login
Copy after login

/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>
Copy after login
Copy after login
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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

/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>
Copy after login
Copy after login
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>
Copy after login
Copy after login

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>
Copy after login

After the soft connection is created, ChongqingNG,

<code>$ cat /etc/hosts 
</code>
Copy after login

Check if there is 127.0.0.1 locahost
If not

<code># echo "127.0.0.1 locahost" >> /etc/hosts
</code>
Copy after login

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>
Copy after login

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?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template