无法访问localhost?

WBOY
Lepaskan: 2016-08-18 09:15:38
asal
1828 orang telah melayarinya

使用的是本机 ubuntu nginx做web服务器,奈何前段时间一直好好的,突然就无法连接localhost了,查了很多资料也无解。
nginx服务处于开启状态如下:

<code>$ sudo service nginx status
 * nginx is running</code>
Salin selepas log masuk
Salin selepas log masuk

/etc/nginx/nginx.conf是默认的没有动过, 其中的include也对,如下:

<code>##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;</code>
Salin selepas log masuk
Salin selepas log masuk

/etc/nginx/site-available中的default,如下:

<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>
Salin selepas log masuk
Salin selepas log masuk

然后访问localhost就如下:

无法访问localhost?

请问是如何解决呢


127.0.0.1也无法访问, 也没有开代理。

回复内容:

使用的是本机 ubuntu nginx做web服务器,奈何前段时间一直好好的,突然就无法连接localhost了,查了很多资料也无解。
nginx服务处于开启状态如下:

<code>$ sudo service nginx status
 * nginx is running</code>
Salin selepas log masuk
Salin selepas log masuk

/etc/nginx/nginx.conf是默认的没有动过, 其中的include也对,如下:

<code>##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;</code>
Salin selepas log masuk
Salin selepas log masuk

/etc/nginx/site-available中的default,如下:

<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>
Salin selepas log masuk
Salin selepas log masuk

然后访问localhost就如下:

无法访问localhost?

请问是如何解决呢


127.0.0.1也无法访问, 也没有开代理。

Nginxubuntu下的架构不同于centoswindows, 通常nginx的所有站点配置都放在/etc/nginx/site-availabl目录下, 但是请注意, 这只是可用的配置, 若你想开启莫条站点的配置比如(www.test.com), 你需要在/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>
Salin selepas log masuk

软连接创建好后, 重庆NG

<code>$ cat /etc/hosts 
</code>
Salin selepas log masuk

找一下 有没有 127.0.0.1 locahost
没有的话

<code># echo "127.0.0.1 locahost" >> /etc/hosts
</code>
Salin selepas log masuk

解决了,但是不太理解;
我把site-available中的default文件 复制一份到/etc/nginx/conf.d/default.conf
然后

<code>sudo nginx -t
sudo service nginx restart</code>
Salin selepas log masuk

就可以了。 不是说/etc/nginx/conf.d/etc/nginx/site-available在他俩任何目录下写配置文件,都可以吗?

是不是防火墙设置问题呢?

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan