无法访问localhost?

php中文网
发布: 2016-08-18 09:15:38
原创
2221人浏览过

使用的是本机 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就如下:

无涯·问知
无涯·问知

无涯·问知,是一款基于星环大模型底座,结合个人知识库、企业知识库、法律法规、财经等多种知识源的企业级垂直领域问答产品

无涯·问知 40
查看详情 无涯·问知

无法访问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/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>
登录后复制

软连接创建好后, 重庆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在他俩任何目录下写配置文件,都可以吗?

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

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号