yum list | grep nginx
出现相似下面的内容,说明yum源是存在的。php
安装命令html
yum install nginx
查看版本nginx
nginx -v
配置目录tc/nginx网络
#运行用户,默认便是nginx,能够不进行设置 user nginx; #Nginx进程,通常设置为和CPU核数同样 worker_processes 1; #错误日志存放目录 error_log /var/log/nginx/error.log warn; #进程pid存放位置 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; #nginx访问日志存放位置 sendfile on; #开启高效传输模式 #tcp_nopush on; #减小网络报文段的数量 keepalive_timeout 65; #保持链接的时间,也叫超时时间 #gzip on; #开启gzip压缩 include /etc/nginx/conf.d/*.conf; #包含的子配置项位置和文件
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; # 配置404页面 # 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; #} }
ps aux | grep nginx
有这三条记录,说明咱们Nginx被正常开启了并发
没有开启app
nginx
启动成功
启动失败,要先杀死nginx,再启动tcp
killall nginx
在从新编写或者修改Nginx的配置文件后,都须要做一下从新载入,这时候能够用Nginx给的命令spa
nginx -s reload
在默认状况下,Nginx启动后会监听80端口,从而提供HTTP访问,若是80端口已经被占用则会启动失败。我么能够使用netstat -tlnp命令查看端口号的占用状况。日志
netstat -tlnp