Linux nginx 问题罗列

    xiaoxiao2022-06-30  151

    1、修改默认访问目录导致页面报错【403 forbidden】

    我的nginx配置如下:

    worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; #charset utf-8; #如果中文乱码可将此注释取消 location / { #root html; #修改前 root /root/webapp/www/static; #修改后 index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { # root html; } } }

    出现这个问题主要是因为others对root目录权限不够(linux的文件权限分为三组,分别是owner、group、others),只需要将others对root的权限添加一个可执行的权限就可以了如:

    chmod 751 /root

    2、nginx页面中文乱码

    网上一般会将中文乱码的原因归结为nginx.conf中没有配置【#charset utf-8;】这个代码,但是我配置了之后还是中文乱码,实际上我的HTML页面是一个最简单的页面:

    <html> <body> <h1>hello world!</h1> <p>我的第一个段落。</p> </body> </html>

    那究竟是哪里不对?

    原因是HTML代码中需要指定编码格式为utf-8,不然就算在nginx.conf中指定了编码格式也没用:

    <meta charset="utf-8"> <html> <body> <h1>hello world!</h1> <p>我的第一个段落。</p> </body> </html>

    在HTML中加入了【<meta charset="utf-8">】代码后,中文显示正常,我事后尝试将nginx.comf中的【#charset utf-8;】注释掉,发现页面也没有产生乱码。


    最新回复(0)