nginx基础(一)
2024-09-06 17:38:49
一、nginx的安装、启动、停止及文件解读
准备工作:
yum -y install gcc gcc-c++ autoconf pcre-devel make automake
yum -y install wget httpd-tools vim
(1)基于Yum的方式安装Nginx
我们可以先来查看一下yum是否已经存在,命令如下:
yum list | grep nginx
配置nginx下载源:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
将上述代码写入 /etc/yum.repos.d/nginx.repo 中
yum install nginx
nginx -v
(2)查看nginx安装目录
rpm -ql nginx
rpm 是linux的rpm包管理工具,-q 代表询问模式,-l 代表返回列表。
(3)nginx.conf文件解读
nginx.conf 文件是Nginx总配置文件,在我们搭建服务器时经常调整的文件。
cd /etc/nginx
vim nginx.conf
#运行用户,默认即是nginx,可以不进行设置
user nginx;
#Nginx进程,一般设置为和CPU核数一样
worker_processes ;
#错误日志存放目录
error_log /var/log/nginx/error.log warn;
#进程pid存放位置
pid /var/run/nginx.pid; events {
worker_connections ; # 单个后台进程的最大并发数
} 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; #nginx访问日志存放位置 sendfile on; #开启高效传输模式
#tcp_nopush on; #减少网络报文段的数量 keepalive_timeout ; #保持连接的时间,也叫超时时间 #gzip on; #开启gzip压缩 include /etc/nginx/conf.d/*.conf; #包含的子配置项位置和文件
(4)default.conf 配置项讲解
进入conf.d目录,然后使用 vim default.conf 进行查看。
server {
listen ; #配置监听端口
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 /.html; # 配置404页面 # redirect server error pages to the static page /50x.html
#
error_page /50x.html; #错误状态码的显示页面,配置后需要重启
location = /50x.html {
root /usr/share/nginx/html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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;
#}
}
得知服务目录放在了/usr/share/nginx/html
下
(5)nginx启动、停止、重启
启动
在centos7以上使用命令 nginx 可直接启动
使用systemctl命令启动 systemctl start nginx.service
使用 ps aux | grep nginx 查看服务开启状况
使用 netstat -lunpt 可查看端口开启状况
停止
nginx -s stop
nginx -s quit
killall nginx
systemctl stop nginx.service
重启
systemctl restart nginx.service
nginx -s reload
最新文章
- C++命名空间问题
- Xcode插件安装
- python模块基础之json,requeste,xml,configparser,logging,subprocess,shutil。
- codeforces #round363 div2.C-Vacations (DP)
- POJ 3258 River Hopscotch (binarysearch)
- MySQL的相关设置
- C语言学习——C和Java语言不同点
- html ui设计案例
- MySQL5.6安装(RPM)笔记
- http目录显示时间与服务器相差8小时
- python制作词云
- Uncaught TypeError: Cannot read property 'getters' of undefined
- 刘志梅 201771010115 《面向对象程序设计(java)》 第十八周学习总结
- kinect 深度图与彩色图对齐程序
- C# ToLookup
- mysql之 OPTIMIZE TABLE整理碎片
- 绝对路径${pageContext.request.contextPath}用法及其与web.xml中Servlet的url-pattern匹配过程
- POJ 2407:Relatives(欧拉函数模板)
- 针对ROS5版本的配置导出和导入(迁移其他服务器)
- jQuery中的text(),html(),val()的区别