1. nginx安装:
安装依赖:
yum install gcc-c++
yum install pcre*
yum install openssl*
yum install zlib*
或则
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
安装nginx
mkdir -p /usr/local/nginx
cd nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz -C nginx
cd nginx
./configure (./configure --help 可以查看编译的参数)
nginx 命令
/usr/local/nginx/sbin/nginx -v //查看版本
/usr/local/nginx/sbin/nginx -t //测试nginx配置文件的准确性
/usr/local/nginx/sbin/nginx -s reload //重载nginx
/usr/local/nginx/sbin/nginx -s stop //停止nginx服务
//查看版本
/usr/local/nginx/sbin/nginx -t //测试nginx配置文件的准确性
/usr/local/nginx/sbin/nginx -s reload //重载nginx
/usr/local/nginx/sbin/nginx -s stop //停止nginx服务
配置nginx
配置nginx运行时使用的用户
groupadd nginx
useradd -g nginx nginx
nginx 配置文件说明
# 运行nginx的所属组和所有者
user nginx nginx;
# 开启一个nginx 工作进程,一般1个cpu核心就写几
worker_processes 1;
# 错误日志路径
#error_log /logs/nginx/error.log;
error_log /logs/nginx/error.log notice;
#error_log logs/error.log info;
# pid 路径
pid /logs/nginx/nginx.pid;
# 一个进程能同时处理1024个请求
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/nginx/access.log main; ## 默认访问日志路径
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; ## 超时时间
#gzip on;
# 开始配置域名 一个server配置端一般对应一个域名
server {
# 在本机所有ip上监听80 ,也可以写为192.168.0.102:80,这样的就只监听192.168.0.102上的80端口
listen 80;
server_name www.heytools.com; # 域名
#charset koi8-r;
#access_log logs/host.access.log main;
location / { # 可以有多个location
root /var/www/html/www.heytools.com; # 站点根目录(程序目录)
index index.html index.htm; #索引文件
}
error_page 404 /404.html; # 定义错误页面,如果是404错误,则把站点根目录下的404.html 返回给用户
# redirect server error pages to the static page /50x.html
# 定义错误页面,如果是404错误,则把站点根目录下的50x.html 返回给用户
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html/www.heytools.com;
}
# 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
# 开始配置bbs.keytools.com
server {
# listen 8000;
listen 80;
server_name bbs.keytoos.com;
location / {
root /var/www/html/bbs.keytools.com;
index index.html index.htm;
}
}
}
测试
创建测试站点
mkdir -p /var/www/html/www.keytools.com
mkdir -p /var/www/html/bbs.keytools.com
echo "www.keytools.com">/var/www/html/www.keytools.com/index.html
echo "bbs.keytools.com">/var/www/html/bbs.keytools.com/index.com
启动nginx ,看到ok 和successful 说明配置文件没有问题
[root@eno-provider-01 sbin]# ./nginx
[root@eno-provider-01 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful