Nginx 基本介绍及安装---(1)
2.Nginx基本安装
2.这里已Centos7版本为例,采用yum源安装
2.1 第一步
2.2 第二部进入Nginx官网获取yum下载源
2.3 yum install nginx 安装
安装完成后可通过nginx -v检查版本 即安装完成
3.基本参数使用
3.1 安装目录
命令 rpm -ql nginx
[root@VM_0_3_centos ~]# rpm -ql nginx /etc/logrotate.d/nginx /etc/nginx /etc/nginx/conf.d /etc/nginx/conf.d/default.conf /etc/nginx/fastcgi_params /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/mime.types /etc/nginx/modules /etc/nginx/nginx.conf /etc/nginx/scgi_params /etc/nginx/uwsgi_params /etc/nginx/win-utf /etc/sysconfig/nginx /etc/sysconfig/nginx-debug /usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /usr/lib64/nginx /usr/lib64/nginx/modules /usr/libexec/initscripts/legacy-actions/nginx /usr/libexec/initscripts/legacy-actions/nginx/check-reload /usr/libexec/initscripts/legacy-actions/nginx/upgrade /usr/sbin/nginx /usr/sbin/nginx-debug /usr/share/doc/nginx-1.18.0 /usr/share/doc/nginx-1.18.0/COPYRIGHT /usr/share/man/man8/nginx.8.gz /usr/share/nginx /usr/share/nginx/html /usr/share/nginx/html/50x.html /usr/share/nginx/html/index.html /var/cache/nginx /var/log/nginx
需要了解的目录
nginx日志切割目录
/etc/logrotate.d/nginx
配置文件
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/nginx.conf
守护进程配置
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
缓存目录
/var/cache/nginx
Nginx日志目录
/var/log/nginx
3.2 编译参数
命令 nginx -V
--with开头的比较复杂 此处不作过多讲解
3.3 Nginx基本配置语法
首先查看配置文件cd /etc/nginx/ cat nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
单个核最大的进程数 一般调节到1万可以满足基本服务要求 常用高性能优化可以设置65535 即端口数附件
HTTP 项目服务配置 一般是通过导入设置(include /etc/nginx/conf.d/*.conf;)
查看/etc/nginx/conf.d/默认配置
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/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 /usr/share/nginx/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; #} }
默认的页面我们页可以看下
根据locattion 路径/usr/share/nginx/html
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
关于http请求作简单介绍,因为Nginx就是作为http代理应用
Ngin启动关闭命令
4. 常见配置
4.1.虚拟机主机配置
为了方便管理和部署业务服务,我们一般基于虚拟主机的方式来配置多业务方式:
方式一:
方式二
方式三:同二差不多
4.2 Nginx日志配置说明
nginx日志分为两类 一类错误日志 一类http监控日志
通过查看nginx.conf可查看对应的日志配置
4.3 Nginx模块讲解
通过nginx -V查看--with开头即为相关模块
这里介绍几个
4.3.1 客户端状态模块配置
它是配置在server 或者location下的用来监控连接状态等信息
4.3.2 随机主页模块(用的少)
4.3.3 HTTP内容替换模块(重要模块)
默认替换一次
通过开关可设置所有内容的替换
那么基础篇就介绍到这里了 请继续关注后续的学习篇