-
下载地址:http://nginx.org/en/download.html
-
安装步骤:
1.安装依赖:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.解压nginx-1.18.0.tar.gz 并重命名为nginx
tar -xzvf nginx-1.18.0.tar.gz
mv nginx-1.18.0 nginx
3.编译,默认安装路径为 /usr/local/nginx
./configure
make
make install
4.启动nginx, 浏览器访问:http:ip,出现下图所示则安装成功
cd /usr/local/nginx/sbin
./nginx
- nginx常用命令
#nginx版本号查看
./nginx -v
#启动nginx
./nginx
#停止nginx
./nginx stop 或者 kill nginx_pid
#重启载入配置文件
./nginx -s reload
#指定配置文件启动
./nginx -c config_path
- nginx安装完成后有以上四个安装目录
conf #所有配置文件目录
nginx.conf #默认的主要配置文件目录
nginx.conf.default #默认模板,初始时与上面的nginx.conf一模一样
html #编译安装时nginx的默认站点目录
50x.html #错误页面
index.html #默认首页
logs #nginx默认日志路径
error.log #错误日志
nginx.pid #nginx启动后的进程id
access.log #nginx访问日志
sbin #nginx命令目录
nginx #nginx shell命令,用于操作nginx命令
- nginx.conf配置
#每个配置项由配置指令和指令参数两部分构成
#user nobody; #指定nginx worker 进程运行及用户组
worker_processes 1; #nginx工作进程的个数,一般配置成cpu核心数
#error_log logs/error.log; #错误日志存放的路径和日志级别
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; #进程PID存放路径
#事件模块指令,用来指定nginx的io模型,nginx支持select,poll,kqueue,epoll等,
#linux系统下首选epoll工作模式
events {
use epoll;
worker_connections 1024; #定义nginx每个进程的最大连接数
#作为服务器而言, 最大并发为 worker_connections * worker_processes
#作为反向代理而言,最大并发为 worker_connections * worker_processes / 2
}
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/access.log main;
sendfile on; #是否开启高效传输模式, on开启 off关闭
#tcp_nopush on; #减少网络报文段的数量
#keepalive_timeout 0;
keepalive_timeout 65; #客户端连接保持活动的超时时间,超过这个时间之后,服务器会关闭该连接
#gzip on;
#虚拟主机配置
server {
listen 80; #虚拟主机服务端口
server_name localhost; #⽤来指定IP地址或域名,多个域名之间⽤空格分开
#charset koi8-r;
#access_log logs/host.access.log main;
#URL地址匹配
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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}