Nginx的概述

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。

Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like协议下发行。其特点是占有内存少,并发能力强,事实上Nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用Nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

Nginx官方网站
Nginx官方文档

Nginx安装配置

环境规划

序号 主机名 IP地址 描述 系统版本
1 linux-node1 eth0:192.168.56.11 Web服务器 CentOS Linux release 7.2

系统优化

  • 关闭selinux和iptables
[root@linux-node1 ~]# setenforce 0
[root@linux-node1 ~]# getenforce
Disabled
[root@linux-node1 ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux[root@linux-node1 ~]# systemctl disable firewalld
[root@linux-node1 ~]# systemctl stop firewalld
  • 同步网络时间服务器
[root@linux-node1 ~]# ntpdate 0.pool.ntp.org
10 Jan 12:38:28 ntpdate[2446]: adjust time server 120.25.115.20 offset 0.048309 sec
[root@linux-node1 ~]# hwclock
Wed 10 Jan 2018 08:31:31 PM CST -0.944430 seconds
[root@linux-node1 ~]# crontab -e
####Synchronization Network Time Server####
*/5 * * * * /usr/sbin/ntpdate 0.pool.ntp.org &>/dev/null
[root@linux-node1 ~]# crontab -l
####Synchronization Network Time Server####
*/5 * * * * /usr/sbin/ntpdate 0.pool.ntp.org &>/dev/null
  • 安装相关依赖包
[root@linux-node1 ~]# yum -y install gcc gcc-c++ zlib-devel gd-devel

安装依赖软件

  • 安装pcre支持正则表达式
[root@linux-node1 ~]# tar xvfz pcre-8.39.tar.gz -C /usr/local/src/
[root@linux-node1 ~]# cd /usr/local/src/pcre-8.39/
[root@linux-node1 pcre-8.39]# ./configure --prefix=/usr/local/pcre-8.39
[root@linux-node1 pcre-8.39]# make && make install
[root@linux-node1 pcre-8.39]# ln -s /usr/local/pcre-8.39/ /usr/local/pcre
[root@linux-node1 pcre-8.39]# ls -l /usr/local/pcre
lrwxrwxrwx 1 root root 21 Feb  9 16:57 /usr/local/pcre -> /usr/local/pcre-8.39/
  • 安装openssl支持加密访问
[root@linux-node1 ~]# tar xvfz openssl-1.0.2a.tar.gz -C /usr/local/src/
[root@linux-node1 ~]# cd /usr/local/src/openssl-1.0.2a/
[root@linux-node1 openssl-1.0.2a]# ./config --prefix=/usr/local/openssl-1.0.2a
[root@linux-node1 openssl-1.0.2a]# make && make install
[root@linux-node1 openssl-1.0.2a]# ln -s /usr/local/openssl-1.0.2a/ /usr/local/openssl
[root@linux-node1 openssl-1.0.2a]# ls -l /usr/local/openssl
lrwxrwxrwx 1 root root 26 Feb  9 17:01 /usr/local/openssl -> /usr/local/openssl-1.0.2a/
  • 安装zlib支持压缩
[root@linux-node1 ~]# tar xvfz zlib-1.2.7.tar.gz -C /usr/local/src/
[root@linux-node1 ~]# cd /usr/local/src/zlib-1.2.7/
[root@linux-node1 zlib-1.2.7]# ./configure --prefix=/usr/local/zlib-1.2.7
[root@linux-node1 zlib-1.2.7]# make && make install
[root@linux-node1 zlib-1.2.7]# ln -s /usr/local/zlib-1.2.7/ /usr/local/zlib
[root@linux-node1 zlib-1.2.7]# ls -l /usr/local/zlib
lrwxrwxrwx 1 root root 22 Feb  9 17:03 /usr/local/zlib -> /usr/local/zlib-1.2.7/
  • 安装geoip支持按地域访问
[root@linux-node1 ~]# tar xvfz GeoIP-1.6.11.tar.gz -C /usr/local/src/
[root@linux-node1 ~]# cd /usr/local/src/GeoIP-1.6.11/
[root@linux-node1 GeoIP-1.6.11]# ./configure
[root@linux-node1 GeoIP-1.6.11]# make && make install
[root@linux-node1 GeoIP-1.6.11]# echo "/usr/local/lib" > /etc/ld.so.conf.d/geoip.conf
[root@linux-node1 GeoIP-1.6.11]# tail -1 /etc/ld.so.conf.d/geoip.conf
/usr/local/lib
[root@linux-node1 GeoIP-1.6.11]# ldconfig

安装Nginx

  • 创建nginx运行用户www
[root@linux-node1 ~]# groupadd -g 60000 www
[root@linux-node1 ~]# useradd -u 60000 -g www -c "Run The Nginx Service" -s /sbin/nologin -M www
[root@linux-node1 ~]# id www
uid=60000(www) gid=60000(www) groups=60000(www)
[root@linux-node1 ~]# grep "\bwww\b" /etc/passwd
www:x:60000:60000:Run The Nginx Service:/home/www:/sbin/nologin
  • 安装nginx
[root@linux-node1 ~]# tar xvfz nginx-1.12.2.tar.gz -C /usr/local/src/
[root@linux-node1 ~]# cd /usr/local/src/nginx-1.12.2/
[root@linux-node1 nginx-1.12.2]# ./configure \
--prefix=/usr/local/nginx-1.12.2 \
--sbin-path=/usr/local/nginx-1.12.2/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www \
--group=www \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_image_filter_module \
--with-http_geoip_module \
--with-pcre=/usr/local/src/pcre-8.39/ \
--with-zlib=/usr/local/src/zlib-1.2.7/ \
--with-openssl=/usr/local/src/openssl-1.0.2a/
[root@linux-node1 nginx-1.12.2]# make && make install
[root@linux-node1 nginx-1.12.2]# ln -s /usr/local/nginx-1.12.2/ /usr/local/nginx
[root@linux-node1 nginx-1.12.2]# ls -l /usr/local/nginx
lrwxrwxrwx 1 root root 24 Feb  9 17:27 /usr/local/nginx -> /usr/local/nginx-1.12.2/
  • 配置文件支持语法检查
[root@linux-node1 ~]# mkdir -p ~/.vim/syntax
[root@linux-node1 ~]# ls -ld ~/.vim/syntax
drwxr-xr-x 2 root root 6 Feb  9 17:28 /root/.vim/syntax
[root@linux-node1 ~]# mv nginx.vim ~/.vim/syntax
[root@linux-node1 ~]# cat >> ~/.vim/filetype.vim<<EOF
au BufRead,BufNewFile /etc/nginx/nginx.conf,/usr/local/nginx/conf/vhost/* set ft=nginx
EOF

编写Nginx控制脚本

[root@linux-node1 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx High Performance Web Server
Documentation=http://nginx.org/en/docs
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target

编辑Nginx主配置文件

[root@linux-node1 ~]# vim /etc/nginx/nginx.conf
user  www www;
worker_processes  8;
worker_cpu_affinity  00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
worker_rlimit_nofile  65535;
pid        /var/run/nginx.pid;events {use epoll;worker_connections  65535;
}http {include       mime.types;default_type  application/octet-stream;charset       utf-8;server_names_hash_bucket_size  128;server_names_hash_max_size  512;large_client_header_buffers  4 64k;client_max_body_size  64m;client_body_buffer_size  1024k;client_header_timeout  15;client_body_timeout  15;send_timeout  30;server_tokens  off;sendfile  on;tcp_nopush  on;tcp_nodelay  on;keepalive_timeout  60;log_format  json  '{"@timestamp":"$time_iso8601", ''"remote_addr": "$remote_addr", ''"remote_user": "$remote_user", ''"body_bytes_sent": "$body_bytes_sent", ''"bytes_sent": "$bytes_sent", ''"request_method": "$request_method", ''"request": "$request", ''"status": "$status", ''"request_time": "$request_time", ''"http_referrer": "$http_referer", ''"http_x_forwarded_for": "$http_x_forwarded_for", ''"http_user_agent": "$http_user_agent", ''"country_code": "$geoip_city_country_code", ''"country_code3": "$geoip_city_country_code3", ''"city_country_name": "$geoip_city_country_name", ''"region_name": "$geoip_region", ''"city_name": "$geoip_city", ''"city_continent_code": "$geoip_city_continent_code", ''"longitude": "$geoip_longitude", ''"latitude": "$geoip_latitude"} ';gzip  on;gzip_min_length  20k;gzip_buffers  8 32k;gzip_http_version  1.1;gzip_comp_level  6;gzip_types  text/plain application/x-javascript text/javascript application/javascript text/css application/x-httpd-php image/jpeg image/gif image/png application/xml text/xml application/rss+xml application/octet-stream application/x-rar-compressed;gzip_vary  on;gzip_disable  "MSIE [1-6]\.";geoip_country  /etc/nginx/conf.d/GeoIP.dat;fastcgi_param  GEOIP_COUNTRY_CODE $geoip_country_code;fastcgi_param  GEOIP_COUNTRY_CODE3 $geoip_country_code3;fastcgi_param  GEOIP_COUNTRY_NAME $geoip_country_name;geoip_city     /etc/nginx/conf.d/GeoLiteCity.dat;fastcgi_param  GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;fastcgi_param  GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;fastcgi_param  GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;fastcgi_param  GEOIP_REGION $geoip_region;fastcgi_param  GEOIP_CITY $geoip_city;fastcgi_param  GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;fastcgi_param  GEOIP_LONGITUDE $geoip_longitude;fastcgi_param  GEOIP_LATITUDE $geoip_latitude;fastcgi_connect_timeout  300;fastcgi_send_timeout  300;fastcgi_read_timeout  300;fastcgi_buffer_size  128k;fastcgi_buffers  8 128k;fastcgi_busy_buffers_size  256k;fastcgi_temp_file_write_size  256k;open_file_cache  max=65535 inactive=20s;open_file_cache_min_uses  1;open_file_cache_valid  60s;server {listen  80 default_server;server_name  _;return  500;}include  /etc/nginx/conf.d/vhost/*.conf;
}
[root@linux-node1 ~]# mkdir /etc/nginx/conf.d/vhost -p
[root@linux-node1 ~]# ls -ld /etc/nginx/conf.d/vhost/
drwxr-xr-x 2 root root 6 Mar 16 14:53 /etc/nginx/conf.d/vhost/
[root@linux-node1 ~]# gunzip GeoIP.dat.gz
[root@linux-node1 ~]# gunzip GeoLiteCity.dat.gz
[root@linux-node1 ~]# mv GeoIP.dat GeoLiteCity.dat /etc/nginx/conf.d/

启动Nginx并设置开机启动

[root@linux-node1 ~]# systemctl start nginx
[root@linux-node1 ~]# systemctl enable nginx
[root@linux-node1 ~]# systemctl status nginx

转载于:https://blog.51cto.com/11097612/2088463

Nginx-1.12.2编译安装相关推荐

  1. 新安装和已安装nginx如何添加未编译安装模块/补丁

    新安装和已安装nginx如何添加未编译安装模块/补丁 --http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10485& ...

  2. 查看nginx php mysql apache编译安装参数

    纯记录 参考链接 http://www.itlearner.com/article/4554 http://bbs.chinaunix.net/thread-926713-1-1.html 查看php ...

  3. 在CentOS 6.9 x86_64的nginx 1.12.2上安装第三方模块set-misc-nginx-module实录

    set-misc-nginx-module模块是标准的HttpRewriteModule指令的扩展,提供更多的功能,如URI转义与非转义.JSON引述.Hexadecimal/MD5/SHA1/Bas ...

  4. CentOS 7下nginx源码包编译安装

    一.下载 nginx 源码包 这里我们选择稳定版: 把下载完的nginx-1.13.12.tar.gz包上传到服务器上 或者可以在服务器上使用终端下载: [root@localhost ~]# cd ...

  5. nginx linux源码编译安装,Linux源码编译安装nginx

    ps:一切从简 一.安装所需环境: yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openss ...

  6. centos 7 nginx hhvm mysql_CentOS 7 编译安装 HHVM 3.4.1

    博客彻底迁移到了DigitalOcean上,无奈囊中羞涩,只能开个512MB内存的Droplet... 只不过,小内存也可以玩出花样.之前就一直想尝试用一下HHVM,无奈编译实在是太麻烦,一直偷懒没使 ...

  7. 为已经安装nginx添加php模块,安装成功的nginx如何添加未编译安装模块

    原已经安装好的nginx,现在需要添加一个未被编译安装的模块: nginx -V 可以查看原来编译时都带了哪些参数 原来的参数: --prefix=/app/nginx 添加的参数: --with-h ...

  8. nginx源码包编译安装

    1.到官方站点卸载nginx-1.6.3版本的源码包 http://nginx.org/en/download.html http://nginx.org 2.安装依赖包和编译工具 yum -y in ...

  9. 源码编译安装LNMP平台(使用Linux, Nginx,MySQL与PHP搭建论坛)

    目录 编译安装NGINX 安装依赖包 新建用户 组便于管理(nginx 服务程序默认 以 nobody 身份运行,建议为其创建专门的用户账户,以便更准确的控制访问权限) 编译安装Nginx 添加 Ng ...

最新文章

  1. 知识产权界福布斯排行榜公布:厉害了,我的中国!
  2. 【杂谈】一本书同时学分类,检测,分割,三维重建,GAN,难道它不香吗?文末送两本
  3. Failed to execute goal on project xxx: Could not resolve dependencies for project com
  4. 列出连通集 (25 分)【DFS与BFS模板】
  5. verilog驱动ADC0809包括仿真测试
  6. oracle update范例,oracle 12c单范例数据库打12.1.0.2.4补丁记录
  7. php影院影城源码,99影院源码 影视网站程序源码/附教程
  8. 工业相机与镜头选型方法(含实例)
  9. Emmagee源码学习
  10. 微信小程序实现二维码签到考勤
  11. 那一年岳云鹏14岁,郭德纲26岁
  12. HTML个人简历代码模板(静态页面)
  13. C语言打印多颜色字体,多功能打印,协助开发调试
  14. (2020版) 墙裂推荐这十款精选 IntelliJ Idea 插件
  15. 云南小学、初中、高中标准教学实验室设备配置清单整体解决方案
  16. 使用Python计算身份证号码最后检验位
  17. 教大家如何利用电脑发射wifi信号 供其他设备免费高速上网!
  18. 计算机被格式化怎么找回资料,电脑分区文件被格式化误删了怎么恢复
  19. 学好数据库,看这9本书就够了
  20. google浏览器chrome无法导入IE收藏夹的问题

热门文章

  1. PHP中空格占位数吗,HTML空格占位
  2. 物体抓取位姿估計算法綜述_大盘点|6D姿态估计算法汇总(上)
  3. 服务器同步什么文件类型,不同服务器同步文件类型
  4. php 语言文件操作,php中目录文件操作详谈
  5. select BUGS
  6. 嵌入式学习笔记——SPI协议
  7. 17.04安装mysql_【17-04-11】 【求助】在线安装mysql时出现问题
  8. 时序分析中的关键术语
  9. 小忆《记录博客一周年》
  10. 连续时间傅里叶变换的性质(简介及推导)