Nginx概述、环境搭建

wget http://nginx.org/download/nginx-1.6.2.tar.gz

yum install -y wget
yum install -y vim-enhanced
yum install -y make cmake gcc gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

tar -zxvf nginx-1.6.2.tar.gz
cd /usr/local/software/nginx-1.6.2
./configure --prefix=/usr/local/software/nginx
make && make install
cd /usr/local/software/nginx
cd /usr/local/software/nginx/sbin/
/usr/local/software/nginx/sbin/nginx
ps -ef|grep nginx
root     18112     1  0 09:57 ?        00:00:00 nginx: master process /usr/local/software/nginx/sbin/nginx
nobody   18114 18112  0 09:57 ?        00:00:00 nginx: worker process               
root     18116 15496  0 09:58 pts/0    00:00:00 grep nginx

http://localhost/
/usr/local/software/nginx/sbin/nginx -s stop
ps -ef|grep nginx
/usr/local/software/nginx/sbin/nginx
/usr/local/software/nginx/sbin/nginx -s reload

nginx documentation

keepalive-download-url-address

cd /usr/local/software/nginx/conf/
vim nginx.conf
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    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  localhost;
        
        location / {
            root   html;
            index  index.html index.htm;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }

修改端口8080

 server {
        listen       8080;
        server_name  localhost;
        
        location / {
            root   html;
            index  index.html index.htm;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
    }


/usr/local/software/nginx/sbin/nginx -s reload
cd /usr/local/software/nginx/html/
vim /usr/local/software/nginx/html/index.html
vim /usr/local/software/nginx/conf/nginx.conf

也可以新增http下的server节点
    server {
        listen       8888;
        server_name  localhost;

        location / {
            root   leon;
            index  index.html;
        }       
    }

cd /usr/local/software/nginx/
mkdir leon
cd /usr/local/software/nginx/leon/
vim index.html
/usr/local/software/nginx/sbin/nginx -s reload
http://localhost:8888/

cat /usr/local/software/nginx/logs/nginx.pid 
ps -ef|grep nginx
tail -f -n 100 /usr/local/software/nginx/logs/access.log 
rm -rf access.log
/usr/local/software/nginx/sbin/nginx -s reload
cat /usr/local/software/nginx/logs/access.log

vim /usr/local/software/nginx/conf/nginx.conf
access_log  logs/access.log  main;
    server {
        listen       8888;
        server_name  localhost;

        access_log  logs/leon.access.log  main;

        location / {
            root   leon;
            index  index.html;
        }
    }

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

       access_log  logs/access80.log  main;

    }
/usr/local/software/nginx/sbin/nginx -s reload

rm -rf access.log
cat access80.log
cat leon.access.log 

cd /usr/local/software/nginx/sbin/
put log.sh
-------------------------------------------------------------------------
#!/bin/sh

BASE_DIR=/usr/local/software/nginx
BASE_FILE_NAME=leon.access.log

CURRENT_PATH=$BASE_DIR/logs
BAK_PATH=$BASE_DIR/datalogs

CURRENT_FILE=$CURRENT_PATH/$BASE_FILE_NAME
BAK_TIME=`/bin/date -d yesterday +%Y%m%d%H%M`
BAK_FILE=$BAK_PATH/$BAK_TIME-$BASE_FILE_NAME
echo $BAK_FILE

$BASE_DIR/sbin/nginx -s stop

mv $CURRENT_FILE $BAK_FILE

$BASE_DIR/sbin/nginx

-------------------------------------------------------------------------
cd /usr/local/software/nginx
mkdir datalogs
chmod 777 /usr/local/software/nginx/sbin/log.sh
crontab -e
* /1 * * * * sh /usr/local/software/nginx/sbin/log.sh
cd /usr/local/software/nginx/datalogs/
vim /usr/local/software/nginx/conf/nginx.conf
    server {
        listen       8888;
        server_name  localhost;

        access_log  logs/leon.access.log  main;

       # location / {
         location ~ test {
            root   leon;
            index  index.html;
        }       
    }
/usr/local/software/nginx/sbin/nginx -s reload
http://localhost:8888/
cd /usr/local/software/nginx/leon/
vim test1234.html
http://localhost:8888/test1234.html
#######firefox设置每次访问时检查缓存
1.在firefox的地址栏上输入about:config回车
2.找到browser.cache.check_doc_frequency选项,双击将3改成1保存即可。

 选项每个值都是什么含义的。请看下面的解释:

0: Once per session 每个进程一次 每次启动Firefox时检查
1: Each time 【开发人员强烈建议开这个】每次访问此页时检查
2: Never
3: When appropriate/automatically 
vim /usr/local/software/nginx/conf/nginx.conf
    server {
        listen       8888;
        server_name  localhost;

        access_log  logs/leon.access.log  main;

       # location / {
         location ~ test {
            if ($remote_addr = 218.17.133.186){
                return 401;
            }
            root   leon;
            index  index.html;
        }
    }


if ($remote_addr = 10.40.8.114){
            return 401
}
/usr/local/software/nginx/sbin/nginx -s reload

if ($http_user_agent ~* firefox) {
vim /usr/local/software/nginx/leon/firefox.html
/usr/local/software/nginx/sbin/nginx -s reload

猜你喜欢

转载自blog.csdn.net/Leon_Jinhai_Sun/article/details/86132270
今日推荐