多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Nginx编译安装[1.12.2] [TOC] ## 1. 安装依赖包 ```sh yum install -y pcre-devel openssl-devel ``` ## 2. 创建虚拟用户,创建目录 ```sh useradd nginx -s /sbin/nologin/ -M mkdir -p /server/tools mkdir -p /app mkdir -p /var/log/nginx mkdir -p /data/html/www ``` ## 3. 下载并安装软件 ```sh cd /server/tools wget http://nginx.org/download/nginx-1.12.2.tar.gz tar xf nginx-1.12.2.tar.gz ``` ## 4. 编译安装 ```sh cd nginx-1.12.2 ./configure \ --prefix=/app/nginx-12.2 \ --user=ngixn --group=nginx \ --with-http_ssl_module \ --with-http_stub_status_module make && make install ``` **参数简述:** ```sh --prefix=PATH 指定软件安装在什么目录下 --user=USER --group=USER 指定软件worker进程管理用户 --with-http_ssl_module 使nginx程序可以支持HTTPsF访问功能 --with-http_stub_status_module 用于监控用户访问nginx服务情况 ``` ## 5. 创建软连接, ```sh ln -s /app/nginx-12.2 /app/nginx ``` ## 6. 精简优化配置文件 改变默认配置文件内容 ```sh cat >/app/nginx/conf/nginx.conf <<"EOF" user nginx; worker_processes auto; error_log /var/log/nginx/error.log error; pid /var/run/nginx.pid; events { worker_connections 1024; } 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; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include mime.types; default_type application/octet-stream; include conf.d/*.conf; } EOF ``` 创建conf.d目录和拷贝默认网页 ```sh mkdir -p /app/nginx-12.2 /app/nginx/conf/conf.d cp -a ./html/* /data/html/ ``` 写入一个默认server ```sh cat >/app/nginx/conf/conf.d/default.conf <<"EOF" server { listen 80; server_name localhost; root /data/html/; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } EOF ``` 以后新增server,按以上内容方式增加即可 ## 7. 创建启停脚本 创建启停脚本[略] 加入开机自启动[略] 启动 ```sh /app/nginx/sbin/nginx ```