yum install gccgcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel make–y

建立nginx的系统用户与组(-r :建立指定系统中的用户、组)

groupadd -r nginx

useradd -s /sbin/nologin -g nginx -r nginx

验证

id nginx

配置nginx的模块

./configure --prefix=/usr \

--sbin-path=/usr/sbin/nginx \

--conf-path=/etc/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_gzip_static_module \

--http-log-path=/var/log/nginx/access.log \

--http-client-body-temp-path=/var/tmp/nginx/client \

--http-proxy-temp-path=/var/tmp/nginx/proxy \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \

--with-http_addition_module \

--with-http_stub_status_module \

--with-http_gunzip_module \

--with-http_auth_request_module \

--with-http_secure_link_module \

--with-http_auth_request_module \

--with-http_realip_module

make && make install

启动nginx

/usr/sbin/nginx -c /etc/nginx/nginx.conf

查看服务是否启动

ps -ef | grep nginx

netstat -antulp | grep nginx

启动的时候会报错,是因为刚才自己手动指定了临时目录,所以这时你要自己手动创建一个这个目录即可。

mkdir /var/tmp/nginx/client -pv

nginx -c /etc/nginx/nginx.conf

停止nginx

从容关闭QUIT

kill -QUIT $(cat /var/run/nginx/nginx.pid)

快速停止

kill -TERM $(cat /var/run/nginx/nginx.pid)

强制结束所有的nginx进程

kill -9 nginx

平滑重启nginx

kill -HUP $(cat /var/run/nginx/nginx.pid)

/usr/sbin/nginx -t -c /etc/nginx/nginx.conf

可以把rpm包中的nginx脚本文件复制过来自己修改后再用

rpm2cpio nginx-1.9.0.rpm | cpio -div  解压rpm包

cp nginx /etc/init.d/

chmod a+x /etc/init.d/nginx

chkconfig --add nginx

chkconfig --list nginx

修改/etc/init.d/nginx脚本文件,否则服务无法用这个脚本启动,因为在安装的过程中,这些都是自己指定的文件和路径。(已修改)

prog=nginx

nginx=${nginx-/usr/sbin/nginx}

conffile=${CONFFILE-/etc/nginx/nginx.conf}

lockfile=${LOCKFILE-/var/lock/nginx.lock}

pidfile=${PIDFILE-/var/run/nginx/nginx.pid}

SLEEPMSEC=100000

RETVAL=0

编译nginx.conf 详解

worker_processes 2  这里建议有几个cpu就分给它几个进程即可。

worker_connections 1024;设置可以最大的连接请求数(默认1024),超过过就在队列里等待

sendfile  on ;  内存分为两段,一段椒user,另一段是kernel,而用户去访问请求时,就会去访问内核,而这个是把访问的这个过程记录下来,放入内存中,而不用每次去内核中读取了。频繁访问东西都会放在内存当中。(是否开启带有缓存的这种机制)

gzip on ;  是否启动压缩功能,在大并发的时候会有所体现。

Location类似于apache的directory,而root旁没写绝对路径那么它的根就是你安装时指定的那个路径。

而这里的/(根)是从/usr/html这里开始的,下面有定义。(从安装路径的html开始)

虚拟主机的配置过程。

我在一个主机里用一个Ip对应多个域名来配置,写在/etc/hosts里

1、虚拟主机配置过程,/etc/nginx/nginx.conf

最后:killall -1 nginx (与service nginx reload结果一样)

建立目录与在目录中写入内容,命令为index.html

mkdir –p/var/www/virtual2

mkdir –p /var/www/virtual

验证:

下面配置文件中会用到大量的正则表达式。

把这个打开

以这个为例,再继续修改配置一下。(warn是日志错误级别)

重启服务,然后日志查看

tailf  /var/log/nginx/www.example.com-error.log

403错误:索引文件未找到

然后自己定义错误页面

编辑/etc/nginx/nginx.conf

接着建立目录,和编辑错误页面的内容

mkdir /var/www/error

cd /var/www/error

echo This is error > 40x.html

接着重启服务并验证结果:

首先:还是继续修改我们的这个配置文件,把我们原有的再进行一下改造即可。

服务重启并验证结果

之前我复制过来的这个文件

别名功能:

1、编辑/etc/nginx/nginx.conf 配置文件。

2、建立目录及索引文件

3、重新启动服务

4、验证结果:

没有明确拒绝都是允许所有

编译安装的时候必须指定这个模块,否则是没有这个功能的。

--with-http_stub_status_module

1、编辑 /etc/nginx/nginx.conf

2、重新启动服务

3、验证结果:

这个nginx_status目录之前是不用建立的,按以上操作完成即可。还可以对这个目录进行加密,不让其他人看到这个结果,这个是可以传给类似ngios与cacti来作监控用的一个功能。

nginx.conf 配置

user  wwwroot;

worker_processes  auto;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections  65535;

}

http {

server_tokens off;

include       mime.types;

default_type  application/octet-stream;

server_names_hash_bucket_size 1024;

variables_hash_max_size 1024;

log_format main  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

sendfile   on;

tcp_nopush on;

tcp_nodelay on;

keepalive_timeout  120;

client_max_body_size 50m;

gzip  on;

gzip_vary on;

gzip_min_length 10240;

gzip_comp_level 9;

gzip_proxied expired no-cache no-store private auth;

gzip_types text/plain text/xml text/css text/comma-separated-values

text/javascript application/x-javascript application/atom+xml

image/jpeg image/gif image/png image/jpg;

gzip_disable "MSIE [1-6]\.";

#open_file_cache          max=102400 inactive=20s;

#open_file_cache_valid    60s;

#open_file_cache_min_uses 5;

#open_file_cache_errors   off;

fastcgi_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=DEDECMS:500m inactive=60m;

fastcgi_cache_key "$scheme$request_method$host$request_uri";

geoip_country /usr/local/nginx/conf/GeoIP.dat;

fastcgi_connect_timeout 3600;

fastcgi_send_timeout 3600;

fastcgi_read_timeout 3600;

fastcgi_intercept_errors on;

server {

listen       80;

server_name  localhost;

return 500;

location / {

root   html;

index  index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

server {

listen       80;

server_name  .example.com;

access_log  logs/example.access.log  main;

location / {

root   html;

index  index.html index.htm;

}

}

include yw.conf;

}

nginx 地址重写规则 泛解析

##start .example.com##

server {

listen       80;

server_name_in_redirect off;

server_name  .example.com;

access_log logs/www.example.com.access.log main;

error_log logs/www.example.com.error.log;

include gen.conf;

if ($host = 'example.com' ) {

rewrite ^/(.*)$ http://www.example.com/$1 permanent;

}

if ($host ~* (\b(?!www\b)[a-zA-Z0-9\-]+).example.com$) {

set $rs1 /$1;

}

set $rootdir /alidata1/web/html/www.example.com$rs1;

root  $rootdir;

location / {

root  $rootdir;

expires 1M;

add_header Cache-Control "public";

index index.html index.htm index.html index.php default.html Default.html;

}

location ~ .*\.(php|php5)?$ {

root  $rootdir;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $rootdir$fastcgi_script_name;

include        fastcgi_params;

}

error_page  404              /404.html;

location = /404.html {

root  /alidata1/web/html/www.example.com;

}

}

##end .example.com##

没有地址重写

##start www.example.com##

server {

listen       80;

server_name_in_redirect off;

server_name  www.example.com;

access_log logs/www.example.com.access.log main;

error_log logs/www.example.com.error.log;

set $rootdir /home/wwwroot/www.example.com;

include gen.conf;

location / {

root  $rootdir;

expires 1M;

add_header Cache-Control "public";

index index.html index.htm index.html index.php default.html Default.html;

}

location ~ .*\.(php|php5)?$ {

root  $rootdir;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $rootdir$fastcgi_script_name;

include        fastcgi_params;

}

error_page  404              /404.html;

location = /404.html {

root  /home/wwwroot/www.example.com;

}

}

##end example.com##

全部反向代理 nginx.conf

upstream proxyserver {

server 114.80.80.41:80 fail_timeout=1s max_fails=1;

server 103.6.222.85:80 backup;

keepalive 20;

}

include proxy.conf;

proxy.conf

server {

server_name  ~^([^\.]+)\.([^\.]+)$ ~^([^\.]+)\.([^\.]+)\.([^\.]+)$  ~^([^\.]+)\.([^\.]+)\.([^\.]+)\.([^\.]+)$;

server_name_in_redirect off;

access_log  logs/access.all.log main;

error_log   logs/error.all.log;

location / {

proxy_pass         http://114.80.80.41;

proxy_redirect     off;

proxy_set_header   Host             $host;

proxy_set_header   X-Real-IP        $remote_addr;

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

add_header X-Cache $upstream_cache_status;

expires 1M;

client_max_body_size       10m;

client_body_buffer_size    128k;

proxy_connect_timeout      90;

proxy_send_timeout         90;

proxy_read_timeout         90;

proxy_buffer_size          4k;

proxy_buffers              4 32k;

proxy_busy_buffers_size    64k;

proxy_temp_file_write_size 64k;

}

}

server {

server_name  google.com www.google.com g.cn www.g.cn;

server_name_in_redirect off;

access_log  logs/g.all.log main;

error_log   logs/g.all.log;

location / {

proxy_pass         https://www.google.com/?gws_rd=ssl;

proxy_redirect     off;

proxy_set_header   Host             $host;

proxy_set_header   X-Real-IP        $remote_addr;

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

add_header X-Cache $upstream_cache_status;

expires 1M;

client_max_body_size       10m;

client_body_buffer_size    128k;

proxy_connect_timeout      90;

proxy_send_timeout         90;

proxy_read_timeout         90;

proxy_buffer_size          4k;

proxy_buffers              4 32k;

proxy_busy_buffers_size    64k;

proxy_temp_file_write_size 64k;

}

}

转载于:https://blog.51cto.com/silencezone/1702114

nginx 安装配置指南相关推荐

  1. 服务器证书安装配置指南(Nginx)-天威诚信

    服务器证书安装配置指南(Nginx) 一.生成证书请求 您需要使用CSR生成工具来创建证书请求.    1.下载AutoCSR:   http://www.itrus.cn/soft/autocsr. ...

  2. GitLab 安装配置指南

    为什么80%的码农都做不了架构师?>>>    GitLab 在 CentOS 7系统上的安装配置指南 1.简单介绍 GitLab 是利用 Ruby on Rails 开发的一个开源 ...

  3. Win10 Terminal + WSL 2 安装配置指南,精致开发体验 - 知乎 (zhihu.com)

    Win10 Terminal + WSL 2 安装配置指南,精致开发体验 - 知乎 (zhihu.com) https://zhuanlan.zhihu.com/p/273237897

  4. codeigniter在nginx安装配置及URL重写

    目录 [hide] 1 codeigniter修改 2 修改nginx配置 3 访问url codeigniter(CI)是一个轻量型的PHP优秀框架,但是它是在apache服务器下开发的,在ngin ...

  5. RabbitMQ快速安装配置指南

    RabbitMQ快速安装配置指南 官网的安装教程由于需要解释原理很多废话,这里总结一下在CentOS7环境下的安装配置过程.如需理解原理,请看官网原文的安装指南或翻译 1. 安装RabbitMQ se ...

  6. puppet 3+Unicorn+Nginx安装配置

    puppet 3+Unicorn+Nginx安装配置 2014-08-15 10:58 酒瓶不倒 酒瓶不倒的博客 字号:T | T 一键收藏,随时查看,分享好友! Unicorn 效率要比 Webri ...

  7. 高可用,完全分布式Hadoop集群HDFS和MapReduce安装配置指南

    原文:http://my.oschina.net/wstone/blog/365010#OSC_h3_13 (WJW)高可用,完全分布式Hadoop集群HDFS和MapReduce安装配置指南 [X] ...

  8. Linux搭建waf防火墙,Linux入门教程:nginx安装配置naxsi waf防火墙,nginxwaf Naxsi 不依赖...

    Linux入门教程:nginx安装配置naxsi waf防火墙,nginxwaf Naxsi 不依赖 Naxsi 是第三方 nginx 模块 ,它和 Modsecurity 都是开源 WAF ,但是它 ...

  9. 教程 | 用安卓手机搭建 web 服务器(二)—— Nginx 安装配置

    上一步完成了必要的软件安装,接下来需要在 Linux 系统上安装 nginx. Nginx("engine x")是一款是由俄罗斯的程序设计师 Igor Sysoev 所开发高性能 ...

最新文章

  1. php 无法输出图像,ThinkPHP里无法输出图片 设置响应头
  2. windows云服务器价格_免费windows云服务器
  3. Underscore.js (1.7.0)-函数预览
  4. Vue.$nextTick
  5. Intellij IDEA 14 安装之后
  6. juniper防火墙策略元素
  7. 男朋友就是要这个样子的
  8. 面向对象19:内部类
  9. kali linux Python开发环境初始化
  10. java留言板源码_jsp留言板示例源码下载(入门级)
  11. 电子绘本pdf_【孩子必看的】20本世界著名英文绘本 | PDF电子版+MP3音频
  12. LeetCode 75. Sort Colors(三颜色排序→K颜色排序)
  13. 数学建模常用算法案例k—means聚类分析
  14. 使用pandoc 生成带中文的pdf
  15. 找一个能随时随地聊天的人很难?不,只是你还不知道Soul App
  16. uni-app学习笔记(1):模板语法
  17. AD软件——把原理图库 和 PCB元件库封装模型 关联起来
  18. 解决VS2010闪退问题
  19. 树莓派之老的方式重刷Raspbian系统-2015
  20. 坚持开源软件的创新之路--陆首群

热门文章

  1. Python计算从n个元素中任选i个的组合数C(n,i)
  2. 二元一次函数最值问题_沪科版八年级上册数学12.3.1一次函数与二元一次方程微课知识点精讲+练习...
  3. php 的点代表什么意思,linux .(点)是什么意思
  4. 运维部门工作总结_我院召开2020年科室(部门)工作总结暨考核测评会议
  5. 文件不混淆_Python代码保护 | pyc 混淆从入门到工具实现
  6. 计算机二级考试c语言公共知识,2016年电大最新计算机二级考试c语言公共基础题知识点.doc...
  7. Enjoy模板里使用layui模板引擎laytpl
  8. mysql字符型数字 按大小排序,类似if判断函数
  9. 计算整数的二进制中包含1的数量
  10. 语音合成论文和英伟达撞车,韩国小哥紧急放出全部草稿代码和样本 | 资源帖...