`

Nginx学习笔记

阅读更多

NGINX相关知识

---------------------------------------

nginx 和 tengine(淘宝)  类似,

1.查看网站的head头:

curl -I www.51cto.com

2.安装nginx步骤:

一。先安装pcre依赖,rewrite需要用:

yum install pcre pcre-devel openssl-devel

二。到http://nginx.org官网下载稳定版本:

tar -zxvf nginx-1.10.2.tar.gz
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx \
 --with-http_ssl_module --with-http_stub_status_module
make && make install
useradd nginx -s /sbin/nologin -M

3.查看安装时的参数:

 ./sbin/nginx -V

4.配置文件:

worker_processes  1;      线程数,配置成CPU核数
worker_connections  1024;   每个worker允许的最大并发数

5.生效配置:

  ./sbin/nginx -t   测试配置文件是否正确

  ./sbin/nginx -s reload  加载配置文件

6.使用include优化配置文件: 

 

include  vhost/*.conf;
7.查看nginx的状态信息:

 

  vim conf/vhost/status.conf

server{
        listen  80;
        server_name     status.wmj.com;
        location / {
          stub_status on;
          access_log  off;
        }
}
 

 

 

8.error日志配置:

 vim conf/nginx.conf

 

error_log  logs/error.log  error;

可以放在  http,server 头里面
9.访问日志配置:

 

 vim conf/nginx.conf

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_time"';
 vim conf/vhost/bbs.conf

 

 

access_log  logs/bbs_access.log main;
 

 10.重定向rewrite的使用:

  

        server {
                listen          80;
                server_name     rewrite.wmj.com;
                access_log  logs/www_access.log main;
                rewrite ^/(.*) http://www.wmj.com/$1 permanent;
}

将"http://rewrite.wmj.com/wmj.html"重定向到"http://www.wmj.com/wmj.html"

permanent: 表示301重定向,没有的话是302

 

  • 大小: 315.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics