CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了笔记:centos6 nginx基本配置测试大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

先安装 pcre pcre-devel openssl-devel 下载nginx并解压 tar xf nginx-1.10.1.tar.gz cd nginx-xxx 配置 ./configure --prefix=/application/nginx-1.10.1 --user=nginx --group=nginx \ --with-http_ssl_module --with-http_s@H_874_5@

先安装

pcre

pcre-devel

openssl-devel


下载Nginx并解压

tar xf Nginx-1.10.1.tar.gz

cd Nginx-xxx


配置

./con@L_944_3@ure --prefix=/application/Nginx-1.10.1 --user=Nginx --group=Nginx \

--with-http_ssl_module --with-http_stub_status_module


创建Nginx用户

useradd Nginx -s /bin/nologin -M && id Nginx


安装

@H_851_14@make && make install


创建软连接(去掉版本号方便使用):

ln -s /application/Nginx-1.10.1/ /application/Nginx


启动

/application/Nginx/sbin/Nginx


检查,用浏览器访问,若连接不上,检查iptable

ps -ef |grep Nginx |grep -v grep && ss -lntup |grep Nginx

curl 127.0.0.1


排错日志

/var/log/messages

/application/Nginx/logs/error.log


配置文件

grep -Ev '#|^$' Nginx.conf


Nginx的参数

-t 检查配置文件语法,reload前需要先执行改命令,另外重启后需要启动检查脚本进行接口探测

-v 版本

-V 查看编译参数

-s 后面追加启动关闭信号参数,reload可以重新读取配置


配置文件配置

1、在http标签里使用include进行分块

include extra/*.conf;

2、在其他conf文件里对虚拟主机进行配置


配置文件

cd /application/Nginx/conf &&\

cat >Nginx.conf<<eof

worker_processes auto;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '

'\$status \$body_bytes_sent "\$http_referer" '

'"\$http_user_agent" "\$http_x_forWARDed_for"';

include /application/Nginx/conf/vhosts/*.conf;

include /application/Nginx/conf/extra/*.conf;

}

eof


附属虚拟主机配置文件

@H_851_14@mkdir -p /application/Nginx/conf/vhosts &&\

cd /application/Nginx/conf/vhosts &&\

touch www.conf &&\

touch /application/Nginx/logs/error_crit_Server1.log &&\

touch /application/Nginx/logs/access_www.log &&\

cat >www.conf<<eof

server {

listen 80;

#配置错误日志的位置和等级,可以使用认的配置

error_log /application/Nginx/logs/error_crit_Server1.log error;

#www.bbb.com bbb.com这个是别名,利用别名可以拿来探测那个服务器访问不正常

server_name localhost www.bbb.com ;

LOCATIOn / {

root html/www;

index www.html index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

LOCATIOn = /50x.html {

root html;

}

#配置访问日志使用off可以禁用访问日志,使用的日志等级需要在主配置文件里配置好等级格式设置

access_log logs/access.log main;

}

eof


使用rewrite配置域名跳转

@H_851_14@mkdir -p /application/Nginx/conf/vhosts &&\

cd /application/Nginx/conf/vhosts &&\

touch rewrite.conf

cat >rewrite.conf<<eof

server {

listen 80;

server_name bbb.com;

rewrite /(.*) http://www.bbb.com/\$1 peRMANent;

}

eof


监控主机的配置文件

@H_851_14@mkdir -p /application/Nginx/conf/extra &&\

touch /application/Nginx/conf/extra/status.conf &&\

cat >/application/Nginx/conf/extra/status.conf<<eof

server{

listen 80;

server_name status.test.org;

LOCATIOn / {

stub_status on;

access_log off;

}

}

eof


将status.test.org加入hosts文件

echo "127.0.0.1 status.test.org" >>/etc/hosts


配置文件的其他参数

log_format 日志格式

access_log 可以在日志参数里加上buffer和flush提升并发性能,甚至可以通过syslog发送到其他地方(为了提高性能,可以设计成在内存里处理后只留下关键信息记录到磁盘上)


使用脚本轮巡日志,把每天的日志进行分割(重命名并清空),写入定时任务0时执行(未测试)

@H_851_14@mkdir -p /application/Nginx/script &&\

cd /application/Nginx/script && touch test.sh &&\

cat >test.sh<<eof

#! /bin/sh

Dateformat="\$(date +%F -d -1day)"

Basedir="/application/Nginx"

Nginxlogdir="\$Basedir/logs"

Logname="access_www.log"

[ -d \$Nginxlogdir ] && cd \$Nginxlogdir ||exit 1

[ -f \$Logname ] || exit 2

cd \$Nginxlogdir

/bin/cp \$Nginxlogdir/\$Logname \$Nginxlogdir/\${Dateformat}_\${LognamE}

>\$Nginxlogdir/\$Logname

eof

大佬总结

以上是大佬教程为你收集整理的笔记:centos6 nginx基本配置测试全部内容,希望文章能够帮你解决笔记:centos6 nginx基本配置测试所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。