nginx安装配置

来源:互联网 发布:淘宝卖保健品怎么样 编辑:程序博客网 时间:2024/06/05 15:39
  1. 安装 nginx 服务:
    wget http://nginx.org/download/nginx-1.9.5.tar.gz
    tar -zxvf nginx-1.5.9.tar.gz
    cd nginx-1.5.9
    mkdir /user/local/nginx159
    ./configure –prefix=/usr/local/nginx159
    报错执行:./configure –prefix=/usr/local/nginx159 –conf-path=/usr/local/nginx159/nginx.conf
    make && make install
  2. nginx 使用
    1. 检查是否安装成功:
    cd /usr/local/nginx159/sbin
    ./nginx -t 出现 is ok 和 test is successful 就算OK 了
    2. 启动:./nginx
    3. 停止:./nginx -s stop
    4. 重启:./nginx -s reload
    或者:重新加载配置文件:./nginx -c /usr/local/nginx/conf.d/nginx_http_auth_es.conf -s reload
    5. 修改了配置文件后最好先检查一下修改过的配置文件是否正确:/usr/nginx/sbin/nginx -t
    6. 页面方式检查是否安装成功
    1. 打开端口: 80
    打开 8080 端口:# /sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
    2. 然后在保存操作:# /etc/rc.d/init.d/iptables save
    3. 查看打开的端口:# /etc/init.d/iptables status
  3. 设置开机启动
    1. 写开机启动脚本:vi nginx 脚本如下,其中红框部分为必须
    2. 放在 /etc/init.d/ 目录下
    3. 给予执行权限:$ chmod 755 nginx
    4. chkconfig –add nginx
    5. chkconfig nginx on
      代码如下:
## chkconfig: - 90 80# description: xxx start/stop/reloadcase "$1" instart)        /usr/local/nginx1119/sbin/nginx -c /usr/local/nginx1119/conf/nginx.conf ;;stop)        /usr/local/nginx1119/sbin/nginx -s stop;;restart)        /usr/local/nginx1119/sbin/nginx restart ;;esac
  1. nginx收集访问日志
    vim nginx_log.conf
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;    log_format main_json '{"createdTime":"$time_local",'                        '"nginxIP":"$server_addr",'                        '"serverIP":"$upstream_addr",'                        '"clientIP":"$remote_addr",'                        '"realClientIP":"$http_x_forwarded_for",'                        '"req_host":"$http_host",'                        '"req_url":"$uri",'                        '"req_method":"$request_method",'                        '"req_remoteUser":"$remote_user",'                        '"req_sessionID":"$cookie_jsessionid",'                        '"req_accessToken":"$http_accesstoken",'                        '"req_referer":"$http_referer",'                        '"req_body":"$request_body",'                        #'"req_body":"-",'                        '"req_length":$request_length,'                        '"req_userAgent":"$http_user_agent",'                        '"request":"$request",'                        '"res_BytesNoHead":$body_bytes_sent,'                        '"res_Bytes":$bytes_sent,'                        '"res_Body":"-",'                        '"connectionID":"$connection",'                        '"connectionID_num":$connection_requests,'                        '"status":$status,'                        '"useTime":$request_time}';    access_log  logs/access.log  main_json;
  1. 如果要获取自定义header里的参数,操作如下:
    修改配置文件fastcgi.conf,加上以下内容
    # vi conf/fastcgi.conf
    添加如下:fastcgi_param HTTP_ACCESSTOKEN $http_accesstoken;
    ngxin日志里添加:‘“accessToken”: “http_accesstoken”, ’

常见问题

异常:centos安装nginx 报错:cp: conf/koi-win' and/usr/local/nginx/conf/koi-win’ are the same file
http://blog.csdn.net/loseleo/article/details/45742237
异常:./configure: error: C compiler cc is not found
http://blog.csdn.net/testcs_dn/article/details/51461750

原创粉丝点击