zoukankan      html  css  js  c++  java
  • nginx 配置

    _____________________________________________________设权限
    sudo chmod -R 777 admin
    _____________________________________________________定时crontab -e
    */1 * * * * sudo chmod -R 777 /phpstudy/admin
    _____________________________________________________.htaccess
    # nginx rewrite rule 
    if (!-e $request_filename) { 
    rewrite ^(.*)$   /index.php?/$1      break;
    }
     
    # end nginx rewrite rule
     
    ——————————————————————.htaccess
    # nginx rewrite rule 
    if (!-e $request_filename) { 
    rewrite ^(.*)$   /index.php?/$1      break;
    }
     
    # end nginx rewrite rule
    ______________________________________________
     
    /phpstudy/server/nginx/sbin/nginx -s reload     nginx重启
     
    service apache restart  apache重启
    /phpstudy/server/httpd/bin/apachectl restart  apache重启
    /phpstudy/server/httpd/bin/apachectl start   apache启动
    ——————————————————
    #user  nobody;
    worker_processes  1;
     
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
     
    #pid        logs/nginx.pid;
     
     
    events {
        worker_connections  1024;
    }
     
     
    http {
        include       mime.types;
        default_type  application/octet-stream;
     
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
     
        #access_log  logs/access.log  main;
     
        sendfile        on;
        #tcp_nopush     on;
     
        #keepalive_timeout  0;
        keepalive_timeout  65;
     
        #gzip  on;
     
        server {
            listen       80;
            server_name  x.com;
     
            #charset koi8-r;
     
            #access_log  logs/host.access.log  main;
       root   /phpstudy/admin/ych;
     
    rewrite ^/(d+).html$ /detail.php?id=$1 last;
    include /phpstudy/admin/ych/webroot/.htaccess;
            location / {
              
                index  index.html index.htm index.php;
            }
     
            #error_page  404              /404.html;
     
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
     
     
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
     
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
    server {
            listen       80;
            server_name  admin.x.com;
     
            #charset koi8-r;
     
            #access_log  logs/host.access.log  main;
       root   /phpstudy/admin/ych_admin;
            location / {
              
                index  index.html index.htm index.php;
            }
     
            #error_page  404              /404.html;
     
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
     
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
     
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
     
     
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
     
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
     
     
        # HTTPS server
        #
        #server {
        #    listen       443;
        #    server_name  localhost;
     
        #    ssl                  on;
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
     
        #    ssl_session_timeout  5m;
     
        #    ssl_protocols  SSLv2 SSLv3 TLSv1;
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers   on;
     
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    include /phpstudy/server/nginx/conf/vhosts/*.conf;
    }
     
    ______________________________生成新站
        /**
         * test
         */
        public function test() {
            define("ROOT",dirname(dirname(dirname(dirname(__FILE__)))));
            define("BROOT",dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
    // echo "<pre>";var_dump(ROOT);exit;
    // $lin=shell_exec('');
    // $test = "sudo chmod -R 777 /phpstudy/admin/ych4"; //ls是linux下的查目录,文件的命令
    // system($test); //执行命令
    // print_r($array);
    echo exec('sudo chmod -R 777 /phpstudy/admin/ych4');
     
    echo ROOT."______________";
    echo BROOT;
    $rs=file_get_contents("root",BROOT."/var/spool/mail/");
    var_dump($rs);
     
    // $output = exec('sudo chmod -R 777 /phpstudy/admin/ych4');
    // echo "<pre>$output</pre>";
     
     
    //    @touch('./install.lock');
        //echo "<pre>";var_dump($_SERVER);exit;
        if($_POST){
            $filepath=$_POST['filepath'];
     
            $site_name=$_POST['site_name'];
            $site_name_s="admin.".$site_name;
            $dirname=$_POST['dirname'];
    $filepath_s=str_replace($dirname,$dirname."_admin",$filepath);
     
            $filename = '/phpstudy/server/nginx/conf/vhosts/phpstudy.conf';
            $somecontent = '
        server {
            listen       80;
            server_name  '.$site_name.';
     
            #access_log  logs/host.access.log  main;
       root   '.$filepath.';
    include /phpstudy/admin/'.$dirname.'/webroot/.htaccess;
            location / {
     
                index  index.html index.htm index.php;
            }
     
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
        }';
    $somecontent2 = '
        server {
            listen       80;
            server_name  '.$site_name_s.';
     
            #access_log  logs/host.access.log  main;
       root   '.$filepath_s.';
    include /phpstudy/admin/'.$dirname.'/webroot/.htaccess;
            location / {
     
                index  index.html index.htm index.php;
            }
     
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
        }';
           if (file_exists ( $filename )) {
               file_put_contents($filename,$somecontent, FILE_APPEND);
           }
     
                if (!$handle = fopen($filename, 'a')) {
                    echo "不能打开文件 $filename";
                    exit;
                }
    copy_dir(ROOT."/ych",ROOT."/".$dirname);
    echo "_____step1";
    fclose($handle);
    $dirname_s=$dirname."_admin";
    copy_dir(ROOT."/ych_admin",ROOT."/".$dirname_s);
    echo "_____step2";
                file_put_contents($filename,$somecontent2, FILE_APPEND);
     
     
                
                echo "<script>alert('success!!');history.go(-1);</script>";
     
        }
     
     
     
     
     
     
     
     
     
     
            
            echo <<<'EOD'
     
    <html>
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
    <center>
        <form method="post">
        <table border="1" width="500">
            <tr>
                <td>
                    网址:
                </td>
                <td>
                    <input type="text" name="site_name" style=" 300px" value="xx3.com"/>
                </td>
            </tr>
            <tr>
                <td>
                    filepath:
                </td>
                <td>
                    <input type="text" name="filepath" style=" 300px"  value="/phpstudy/admin/ych3/webroot"/>
                </td>
            </tr>
     
    <tr>
                <td>
                    dirname:
                </td>
                <td>
                    <input type="text" name="dirname" style=" 300px"  value="ych3"/>
                </td>
            </tr>
            
            <tr>
                <td colspan="2" align="center">
                    <input type="submit"  value="submit"/>
                    <a href="index.php"> <input type="button"  value="reback"/></a>
                </td>
            </tr>
        </table>
        </form>
    </center>
     
    </body>
    </html>
    EOD;
    //        $this->display('user/branch_list', $data);
        }
     
     
    ————————————多站点
    server {
            listen       80;
            server_name  admin.x.com;
     
            #charset koi8-r;
     
            #access_log  logs/host.access.log  main;
       root   /phpstudy/admin/ych_admin/webroot;
    include /phpstudy/admin/ych_admin/webroot/.htaccess;
            location / {
              
                index  index.html index.htm index.php;
            }
     
            #error_page  404              /404.html;
     
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
     
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
     
        }
     
        server {
            listen       80;
            server_name  xx8.com;
     
            #access_log  logs/host.access.log  main;
       root   /phpstudy/admin/ych8/webroot;
    include /phpstudy/admin/ych8/webroot/.htaccess;
            location / {
     
                index  index.html index.htm index.php;
            }
     
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
        }
        server {
            listen       80;
            server_name  admin.xx8.com;
     
            #access_log  logs/host.access.log  main;
       root   /phpstudy/admin/ych8_admin/webroot;
    include /phpstudy/admin/ych8/webroot/.htaccess;
            location / {
     
                index  index.html index.htm index.php;
            }
     
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
     
          location ~ .php(.*)$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info  ^((?U).+.php)(/?.+)$;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO  $fastcgi_path_info;
                fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
                include        fastcgi_params;
            }
        }
     
     
     
    __________________________设置Nginx作为缓存
    完整的配置文件nginx.conf
    1. #user  nobody;  
    2. worker_processes  1;  
    3.   
    4. events {  
    5.     worker_connections  1024;  
    6. }  
    7.   
    8.   
    9. http {  
    10.     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
    11.                       '$status $body_bytes_sent "$http_referer" '  
    12.                       '"$http_user_agent" "$http_x_forwarded_for"';  
    13.   
    14.     access_log  logs/access.log  main;  
    15.   
    16.     #source site ip and port  
    17.     upstream contactpool{  
    18.         server 106.38.193.183:80;  
    19.     }  
    20.   
    21.     #proxy cache info  
    22.     proxy_connect_timeout 5;  
    23.     proxy_read_timeout 60;  
    24.     proxy_send_timeout 5;  
    25.     proxy_buffer_size 16k;  
    26.     proxy_buffers 4 64k;  
    27.     proxy_busy_buffers_size 128k;  
    28.     proxy_temp_file_write_size 128k;  
    29.     proxy_temp_path /home/temp_dir;  
    30.     proxy_cache_path /home/cache  
    31.                     levels=1:2  
    32.                     keys_zone=cache_one:50m  
    33.                     inactive=20m  
    34.                     max_size=30g;  
    35.   
    36.     server {  
    37.         listen       80;  
    38.         server_name  localhost;  
    39.   
    40.         location / {  
    41.             #proxy cache info  
    42.             index  index.html index.htm index.php;  
    43.             proxy_cache cache_one;  
    44.             proxy_cache_valid 200 302 1h;  
    45.   
    46.             proxy_cache_key $host$uri$is_args$args;  
    47.             proxy_pass   http://contactpool;  
    48.             proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; # 不处理后端服务器返回的指定响应头    
    49.   
    50.             expires 30d;  
    51.             proxy_set_header Host $host;  
    52.             proxy_set_header X-Real-IP $remote_addr;  
    53.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    54.         }  
    55.     }  
    56.   
    57. }  
     

     1.2 测试

            curl www.guowenyan.cn/test.html

            用户第一次请求一个url,nginx会回源,将结果返回给用户的同时,把结果缓存;

            第二次再请求该url时,nginx直接将结果返回给用户,无需回源。 

            是否回源,我是通过在nginx上抓包看的。

  • 相关阅读:
    table表格宽带研究(附带:table表格为什么设置td宽度无效)
    同一天有重复请假
    C#通过SQL 添加,删除,或者修改表名。
    将数据导出到Excel2007格式。
    MRBS, meeting room manager system,会议预定管理系统
    于网站主机,DNS,域名解析,Web服务器关系详解
    关于启明星系统(OA系统,预定系统,请假系统等)开始ASP.NET身份验证
    启明星系统字体的演变
    从网易获取股票每日交易数据的爬虫程序
    如何让Web程序在点击按钮后出现如执行批处理程序般的效果
  • 原文地址:https://www.cnblogs.com/csjoz/p/7243998.html
Copyright © 2011-2022 走看看