• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

无法访问localhost?

php 搞代码 3年前 (2022-01-23) 19次浏览 已收录 0个评论
文章目录[隐藏]

<body>

使用的是本机 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: Yo<em>/本2文来源[email protected]搞@^&代*@码2网</em><strong>搞gaodaima代码</strong>u 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就如下:

请问是如何解决呢


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

回复内容:

<body>

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

请问是如何解决呢


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 -tsudo service nginx restart</code>

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

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:无法访问localhost?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址