浅谈nginx(配置篇)

发表于 2019-10-08  1.02k 次阅读



nginx配置文件讲解
nginx 配置文件nginx.conf中
server{        以下为http配置
   listen  80; 指定http端口
   server_name   xxx.bbb.ccc;   域名:xxx.bbb.ccc
   root   /www/bbb;  
   指网站项目存放位置,例如/www/bbb 其中存放在不是nginx 同一路径下一律要使用绝对路径以/开头
   index  test.html index.php index.html index.htm;
   指定首页文件,例如test.html等等,其中它是向下匹配的从text..html匹配到index.htm  
   access_log  /data/logs/gwaccess.log   main;               
   指定该网站运行的日志存放位置
   error_log   /data/logs/gwerror.log    error;              
   指定该网站发生错误时的日志存放位置
   charset    utf-8;           
   设置该网站的字符集 例如此处为utf-8
   location /  {            指网站项目存放位置
       root /www//bbb;      设置文件位置
       index test.html index.php index.html index.htm;    指定首页文件
              }
   location /files/ {        
   设置文件位置,其中这个files/后面的这个/比如要加上,不然会导致文件目录穿越漏洞     
        alias /home/;   设置别名位置
               }
   location /images/ {                          设置图片使用路径
        root     /www/images;                   设置图片存放位置
         autoindex on;                          开启浏览,但是会存在文件遍历漏洞,建议设置为off
      }
     error_page 500 502 503 504 /50x.html;           设置500,502,503,504错误都使用50x页面
   location = /50x.html {                            设置50x错误页面
          root html;                                  设置50x错误页面位置
          }
   location ~ \.php$ {                     设置php网站页面
      root html;                           设置php项目文件
      fastcgi_pass 127.0.0.1:9000;         转发给php-fpm处理php文件
      fastcgi_index index.php;             设置php页面首页
      fastcgi_param SCRIPT_FILENAME = $fastcgi_script_name    访问时读取php文件
      include fastcgi_params;
         }
server{          以下为https配置
    listen 443 ssl;   设置https端口默认为443
    server_name    xxx.bbb.ccc;   设置域名
    ssl_certificate      /usr/local/key/xxx.bbb.ccc.crt;  设置证书文件
    ssl_certificate_key  /usr/local/key/xxx.bbb.ccc.key;  设置私钥文件
    ssl_session_cache shared:SSL:1m;                      设置缓存大小
    ssl_session_timeout 5m;                               设置超时时间
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 
    设置https证书加密类型
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   设置https加密协议
    ssl_prefer_server_ciphers on;          依赖SSLv3和TLSv1协议的服务器密码将优先于客户端密码
    location / { 
       root /www//bbb;
        index test.html index.php index.html index.htm; 
        } 
   error_page 500 502 503 504 /50x.html;
    location = /50x.html {
      root html; 
       }
   }
                  


 

本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

0