首頁  >  文章  >  後端開發  >  無法存取localhost?

無法存取localhost?

WBOY
WBOY原創
2016-08-18 09:15:381765瀏覽

使用的是本機 ubuntu nginx做web伺服器,奈何前段時間一直好好的,突然就無法連接localhost了,查了很多資料也無解。
nginx服務處於開啟狀態如下:

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

/etc/nginx/nginx.conf是預設的沒有動過, 其中的include也對,如下:

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

/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>

然後訪問localhost就如下:

無法存取localhost?

請問是如何解決呢


127.0.0.1也無法訪問, 也沒有開代理。

回覆內容:

使用的是本機 ubuntu nginx做web伺服器,奈何前段時間一直好好的,突然就無法連接localhost了,查了很多資料也無解。
nginx服務處於開啟狀態如下:

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

/etc/nginx/nginx.conf是預設的沒有動過, 其中的include也對,如下:

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

/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>

然後訪問localhost就如下:

無法存取localhost?

請問是如何解決呢


127.0.0.1也無法訪問, 也沒有開代理。

Nginxubuntu下的架構不同於centoswindows, 通常nginx的所有站點配置都放在/etc/只是可用的配置, 若你想開啟莫條站點的配置例如(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>
軟連結創建好後, 重慶

NG

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

找一下 有沒有 127.0.0.1 locahost

沒有的話

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

解決了,但是不太理解;

我把
site-available中的default檔案 複製一份到/etc/nginx/conf.d/default.conf然後

<code>sudo nginx -t
sudo service nginx restart</code>
就可以了。 不是說

/etc/nginx/conf.d/etc/nginx/site-available在他倆任何目錄下寫配置文件,都可以嗎?

是不是防火牆設定問題呢?

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn