nginx1.22安装部署
一键安装(推荐):
cd /usr/local/src && rm -rf ay_sh && yum install git && git clone https://gitee.com/whatever0/ay_sh.git && sh ay_sh/nginx_setup.sh
自行安装
1. 获取nginx
cd /usr/local/src && wget https://nginx.org/download/nginx-1.22.0.tar.gz
或者直接下载再上传
2. 解压
tar -xvhf nginx-1.22.0.tar.gz
cd nginx-1.22.0
3. 安装相关依赖
yum -y install gcc pcre-devel zlib zlib-devel
4. 配置
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_realip_module
5. 编译&安装
make && make install
目录:
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
6. 添加环境变量
echo -e '# nginx\nPATH=$PATH:/usr/local/nginx/sbin/nginx' >> /etc/profile && . /etc/profile # -e 支持换行
7. 启动命令
nginx
8. 验证
curl http://0.0.0.0:80 # --dump 纯文本显示
9. 配置文件详解(/usr/local/nginx/conf/nginx.conf)
# 启动子进程默认用户
#user nobody;
# 一个主进程和多个工作进程。工作进程是单进程的,切不需要特殊授权即可运行;这里定义的是工作进程数量
worker_processes 1;
# 全局错误日志的位置及日志格式
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
# 每个工作进程最大的并发数
worker_connections 1024;
}
# http服务器设置
http {
# 设定mime类型,类型由mime.type文件定义
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"';
#$remote_addr与$http_X_forwarded_for用以记录客户端的ip地址;
#$remote_user:用来记录客户端用户名称;
#$time_local:用来记录访问时间与时区;
#$request:用来记录请求的url与http协议;
#$status:用来记录请求状态;成功是200
#$body_bytes_sent:记录发送给客户端文件主体内容大小;
#$http_referer:用来记录从哪个页面链接访问过来的;
#$http_user_agent:记录客户浏览器的相关信息。
# 全局访问日志路径
#access_log logs/access.log main;
# sendfile指令指定 nginx是否调用sendfile函数(zero copy 方式来输出文件,对于普通应用,必须设为on。)
sendfile on;
# 此选项允许或禁止使用socket的TCP_CORK的选项,仅在使用sendfile的时候使用
#tcp_nopush on;
# 长连接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
# 开启压缩
#gzip on;
# 配置虚拟主机
server {
# 虚拟主机使用的端口
listen 80;
# 虚拟主机域名
server_name localhost;
# 虚拟主机支持的字符集,只对当前server生效
charset utf-8;
# 虚拟主机的访问日志路径
#access_log logs/host.access.log main;
# 定义web根路径
# 这里的location路径匹配,如果是root,就是一个web站点功能
# 如果写的是proxy_pass参数,就是一个请求转发,反向代理功能
location / {
# 根目录路径
#root html;
# 索引页
# index index.html index.htm;
# 通过uwsgi_pass把请求转发给后端的uwsgi服务器
uwsgi_pass 0.0.0.0:8000;
# 这个参数固定,添加一些转发请求头内容
include uwsgi_params;
}
# 配置静态文件集合路径 --静态文件关键
location /static {
alias /staticfiles;
}
#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;
}
# 定义反向代理服务器 数据服务器是lamp模型
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# 定义PHP为本机服务的模型
# 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
#
# 拒绝apache DR目录及子目录下的.htaccess文件访问
#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的配置方案
# 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;
# }
#}
}

浙公网安备 33010602011771号