Linux nginx 問題羅列

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;】註釋掉,發現頁面也沒有產生亂碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章