加入收藏 | 设为首页 | 会员中心 | 我要投稿 十堰站长网 (https://www.0719zz.com/)- 混合云存储、网络、视频终端、云计算、媒体处理!
当前位置: 首页 > 运营中心 > LNMP > 正文

linux服务器下LNMP安装与配置方法

发布时间:2023-02-20 09:57:06 所属栏目:LNMP 来源:互联网
导读:注意:关闭rpm默认安装的apache和mysql 1.准备php函数的rpm包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2

              fastcgi_index  index.php;
          #   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
              include        fastcgi_params;
          }
 
  最后在客户端测试虚拟主机www.baidu.com和www.sina.com两家公司网站
 
  21.列表页显示
  location / {
              autoindex on;           #打开列表页
              root   html;
              index  index.html index.php index.htm;
           }
 
  22.虚拟目录设置
  location /bbs{
                  alias /mnt/bbs/;
          }
  #这样配置html静态文件是可以出来的,但是php动态页面出不来,而且会浏览器的页面上会显示" No input file specified. "的报错,其实是php系统文件地址( SCRIPT_FILENAME)找不到,也就是说fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;中的$document_root$fastcgi_script_name不是真正的/mnt/bbs/index.php的地址,这可怎么解决:
  location /bbs {
              alias /mnt/bbs/;
              index bbs.php index.html index.php;
          }
          location ~ ^/bbs/ {
              root /mnt/;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
                       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
              include        fastcgi_params;
              log_format  bbs  '$document_root$fastcgi_script_name ';
              access_log logs/bbs.access.log bbs;
          }
  #后面两行是关于日志的,就是为了更好的观察由nginx提交给fastcgi的php的系统地址SCRIPT_FILENAME,在这里我用$request_filename来给SCRIPT_FILENAME赋值,在日志中的结果为/mnt/bbs/index.php,在这里我发现一个问题就是$request_filename中的root设置为/mnt,否则$request_filename的值为:/mnt/bbs/bbs/index.php.
 
  由以上可以得到一个结论,就是默认php设置也可以这样设置关于SCRIPT_FILENAME:
  location ~ .php$ {
              root           html;
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index  index.php;
              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
              include        fastcgi_params;
              log_format  php  '$document_root$fastcgi_script_name ';
              access_log logs/php.access.log php;
          }
  #此时从日志中可以看到,$request_filename的值为/usr/local/nginx/html/index.php,而以前默认的/scripts$fastcgi_script_name显然是错的php系统地址,日志中显示为/scripts/index.php
  23.nginx状态监控
  location /nginxstatus{
          stub_status on;
          access_log  off;
          }
  #客户端访问网址:http://www.baidu.com/nginxstatus
 
  24.rewrite正则过滤
  location ~ .php$ {
          proxy_pass   http://127.0.0.1;
          }
  Rewrite指令最后一项参数为flag标记,支持的flag标记如下:
  Last 标示完成rewrite规则
  Break 不再匹配后面的规则
  Redirect 302临时重定向
  Permanent 301永久重定向
  Last和break用来实现uri重写,浏览器地址栏的url地址不变,但在服务器访问的路径发生了变化,redirect和permanent用来实现url跳转,浏览器地址栏会显示跳转后的url地址,使用alias指令时必须使用last标记,使用proxy_pass指令时要使用break标记,last标记在本条rewrite规则执行完毕后,会对其所在的server{}标签重新发起请求,而break标记则在本条规则匹配完成后,终止匹配,不再匹配后面的规则.
 
  在匹配的过程中,nginx将首先匹配字符串,然后再匹配正则表达式,匹配到第一个正则表达式后,会停止搜索,如果匹配到正则表达式,则使用正则表达式的搜索结果,如果没有匹配到正则表达式,则使用字符串的搜索结果.
  可以使用前缀"^~"来禁止匹配到字符串后,再去检查正则表达式,匹配到url后,将停止查询.
  使用前缀"="可以进行精确的url匹配,如果找到匹配的uri,则停止查询,例如"location=/",只能匹配到"/",而"/test.html"则不能被匹配.
  正则表达式的匹配,按照它们在配置文件中的顺序进行,写在前面的优先.
  Location = / {
         #仅仅匹配 /
      [configuration A]
  }
  Location / {
         #匹配任何以/开头的查询,但是正则表达式及较长的字符串(/bbs/)将被优先匹配.
      [configuration B]
  }
  Location ^~ /images/ {
         #匹配任何以/images/开头的字符串,并且停止搜索,所以正则表达式将不会被检查.
      [configuration C]
  }
  Location ~* .(gif|jpg|jpeg)$ {
         #匹配以.gif、.jpg、.jpeg结尾的任何请求,但是,/images/内的请求将使用configuration c的配置
         [configuratoin D]
  }
  请求处理匹配结果示例:
  / -> configuration A;
  /documents/document.html -> configuration B;
  /images/1.gif -> configuration c;
  /documents/1.jpg -> configuration D;
 
  例1:域名跳转
  输入www.sina.com,跳转到www.sohu.com
      server {
          listen       80;
          server_name  www.sina.com;
          access_log  logs/sina.access.log  main;
          location / {
              root   /web/sina;
              index  index.html index.htm;
                       if (-e $request_filename){

(编辑:十堰站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读