1.安装nginx
yum install nginx
2.卸载
1.暂停nginx
systemctl stop nginx.service
2.删除
yum remove nginx
3.主要操作目录
4常用配置
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
#全局配置的段
#用户名 默认
user nginx;
#进程形式 自动开启
worker_processes auto;
#错误日志文件
error_log /var/log/nginx/error.log;
#nginx是一个程序,既然是一个程序,则需要一个进程来运行,指定的进程号
#cd /run/nginx
#cat nginx.pid会得到一个进程号码
#如果没有nginx.pid需要进行启动nginx
#启动 service nginx start
#
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
#指定最多连接数量
events {
worker_connections 1024;
}
#http配置段,server一些通用设置
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#log日志配置段
access_log /var/log/nginx/access.log main;
# 开启高效文件传输模式
sendfile on;
# 防止网络阻塞
tcp_nopush on;
# 防止网络阻塞
tcp_nodelay on;
# 长连接超时时间,单位是秒
keepalive_timeout 65;
#散列冲突
types_hash_max_size 2048;
#nginx可以处理的文件类型mime.types
include /etc/nginx/mime.types;
# 默认文件类型
default_type application/octet-stream;
# 开启gzip压缩输出
#gzip on;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
#导入 server配置段内容
include /etc/nginx/conf.d/*.conf;
#############server可以在http内配置,也可以在其他路径配置/etc/nginx/conf.d/*.conf################
server {
#listen 端口;
#server_name 主机名;
#listen 80 default_server;
#listen [::]:80 ipv6only=on default_server;
listen 1.15.150.80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#匹配根路径
location / {
root /etc/nginx/html;
index index.html;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
####################################################################
# server {
# root /usr/share/nginx/html;
# listen 1.15.150.80:80;
# location / {
# root /etc/nginx/html;
# index index.html;
# }
# }
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /404.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
###最后要在服务器端 nginx -s reload
#错误:nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
#sudo nginx -c /etc/nginx/nginx.conf # 指定nginx配置文件
#sudo nginx -s reload # 重新启动nginx