Linux nginx 安装配置,nginx安装配置
Linux nginx 安装配置,nginx安装配置
nginx 安装与配置
Linux安装nginx :
使用root用户 yum install -y nginx
nginx 安装目录为/etc/nginx,配置文件为/etc/nginx/nginx.conf
nginx 简单配置:端口转发
user nginx; //定义Nginx运行的用户和用户组
worker_processes auto; //nginx进程数,建议设置为等于CPU总核心数。
error_log /var/log/nginx/error.log 日志类型;//日志路径 ,以及日志类型可进行配置(info|debug|notic|warn|error|crit)
pid /run/nginx.pid; //进程文件
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events { //工作模式与连接数上限
worker_connections 1024;//单个进程最大连接数(最大连接数=连接数*进程数)
}
http {//设定http服务器
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; //开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
tcp_nopush on;//防止网络阻塞
tcp_nodelay on;//防止网络阻塞
keepalive_timeout 65; //长连接超时时间,单位是秒
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 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.
include /etc/nginx/conf.d/*.conf;
//虚拟主机的配置
server {
listen 80 default_server; 监听端口
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
//启用反向代理
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://127.0.0.1:8888;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
评论暂时关闭