2019独角兽企业重金招聘Python工程师标准>>>

Nginx安装目录概要

  • cd /usr/local/src
  • wget http://nginx.org/download/nginx-1.12.1.tar.gz
  • tar zxf nginx-1.12.1.tar.gz
  • ./configure --prefix=/usr/local/nginx
  • make && make install
  • vim /etc/init.d/nginx //复制如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx )
  • chmod 755 /etc/init.d/nginx
  • chkconfig --add nginx
  • chkconfig nginx on
  • cd /usr/local/nginx/conf/; mv nginx.conf nginx.conf.bak
  • vim nginx.conf //写入如下内容(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf)
  • /usr/local/nginx/sbin/nginx -t
  • /etc/init.d/nginx start
  • netstat -lntp |grep 80

Nginx安装

  1. 切换到/usr/local/src/目录下
[root@hanfeng ~]# cd /usr/local/src/
[root@hanfeng src]#
  1. 下载Nginx安装包
  • wget http://nginx.org/download/nginx-1.12.1.tar.gz
[root@hanfeng src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
  1. 解压安装包
[root@hanfeng src]# tar zxf nginx-1.12.1.tar.gz
[root@hanfeng src]#
  1. 切换到nginx-1.12.1目录下
[root@hanfeng src]# cd nginx-1.12.1
[root@hanfeng nginx-1.12.1]#
  1. 初始化./configure --prefix=/usr/local/nginx
[root@hanfeng nginx-1.12.1]# ./configure --prefix=/usr/local/nginx
  1. 然后编译make && make install
[root@hanfeng nginx-1.12.1]# make && make install

7查看nginx目录

  • conf目录,就是配置文件目录
  • html目录,样例文件
  • logs目录,存放日志的
  • sbin目录,核心进程目录
[root@hanfeng nginx-1.12.1]# ls /usr/local/nginx/
conf  html  logs  sbin
[root@hanfeng nginx-1.12.1]#
  1. 支持-t 检查配置文件语法错误
[root@hanfeng nginx-1.12.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hanfeng nginx-1.12.1]#
  1. 给nginx创建启动脚本,放在/etc/init.d/nginx,配置文件内容
[root@hanfeng nginx-1.12.1]# vim /etc/init.d/nginx将以下文件拷贝进去
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{echo -n $"Starting $prog: "mkdir -p /dev/shm/nginx_tempdaemon $NGINX_SBIN -c $NGINX_CONFRETVAL=$?echoreturn $RETVAL
}
stop()
{echo -n $"Stopping $prog: "killproc -p $NGINX_PID $NGINX_SBIN -TERMrm -rf /dev/shm/nginx_tempRETVAL=$?echoreturn $RETVAL
}
reload()
{echo -n $"Reloading $prog: "killproc -p $NGINX_PID $NGINX_SBIN -HUPRETVAL=$?echoreturn $RETVAL
}
restart()
{stopstart
}
configtest()
{$NGINX_SBIN -c $NGINX_CONF -treturn 0
}
case "$1" instart)start;;stop)stop;;reload)reload;;restart)restart;;configtest)configtest;;*)echo $"Usage: $0 {start|stop|reload|restart|configtest}"RETVAL=1
esac
exit $RETVAL然后保存退出
  1. 更改配置文件的权限
[root@hanfeng nginx-1.12.1]# chmod 755 /etc/init.d/nginx
[root@hanfeng nginx-1.12.1]#
  1. 将nginx加入到服务列表里
[root@hanfeng nginx-1.12.1]# chkconfig --add nginx
[root@hanfeng nginx-1.12.1]#
  1. 配置开启启动nginx服务
[root@hanfeng nginx-1.12.1]# chkconfig nginx on
[root@hanfeng nginx-1.12.1]#
  1. 定义配置文件,默认conf目录下是有一个nginx.conf文件的,但我们不使用它,使用自己配置的
[root@hanfeng nginx-1.12.1]# cd /usr/local/nginx/conf/
[root@hanfeng conf]# ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
[root@hanfeng conf]# mv nginx.conf nginx.conf.1
[root@hanfeng conf]#
  1. 创建一个配置文件,配置文件内容
[root@hanfeng conf]# vim nginx.conf在配置文件中添加以下内容
user nobody nobody;    // user定义启动nginx的用户
worker_processes 2;    //定义子进程有几个
error_log /usr/local/nginx/logs/nginx_error.log crit;   //错误日志
pid /usr/local/nginx/logs/nginx.pid;  // PID所在
worker_rlimit_nofile 51200;   //nginx最多可以打开文件的上限
events
{
use epoll;                                   //使用epoll模式
worker_connections 6000;      // 进程最大有多少个连接
}http
{include mime.types;default_type application/octet-stream;server_names_hash_bucket_size 3526;server_names_hash_max_size 4096;log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'' $host "$request_uri" $status'' "$http_referer" "$http_user_agent"';sendfile on;tcp_nopush on;keepalive_timeout 30;client_header_timeout 3m;client_body_timeout 3m;send_timeout 3m;connection_pool_size 256;client_header_buffer_size 1k;large_client_header_buffers 8 4k;request_pool_size 4k;output_buffers 4 32k;postpone_output 1460;client_max_body_size 10m;client_body_buffer_size 256k;client_body_temp_path /usr/local/nginx/client_body_temp;proxy_temp_path /usr/local/nginx/proxy_temp;fastcgi_temp_path /usr/local/nginx/fastcgi_temp;fastcgi_intercept_errors on;tcp_nodelay on;gzip on;gzip_min_length 1k;gzip_buffers 4 8k;gzip_comp_level 5;gzip_http_version 1.1;gzip_types text/plain application/x-javascript text/css text/htm application/xml;server        //一个server 对应一个虚拟主机,定义这个,才能正常访问网站  下面一整段,就是一个默认的虚拟主机{listen 80;server_name localhost;            //网站域名index index.html index.htm index.php;root /usr/local/nginx/html;            //网站的根目录location ~ \.php$                         //配置解析php的部分{include fastcgi_params;fastcgi_pass unix:/tmp/php-fcgi.sock;        //nginx通过这一行配置来调用php-fpm服务# fastcgi_pass 127.0.0.1:9000;            //如果php-fpm监听的是9000端口,直接这样写配置即可fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;}    }
}然后保存退出
  • 作为一个网站的服务,必须监听一个端口,默认监听的是80端口,假如没有配置 server 这个几行,那么nginx将识别不到监听端口,导致服务不可用
  1. 编译好配置文件,检查配置文件是否存在语法错误
[root@hanfeng conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@hanfeng conf]# 
  1. 启动nginx服务
[root@hanfeng conf]# /etc/init.d/nginx  start
Starting nginx (via systemctl):                            [  确定  ]
[root@hanfeng conf]# 
  1. 查看nginx进程
[root@hanfeng conf]# ps aux |grep nginx
root     16411  0.0  0.0  20996   624 ?        Ss   21:53   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   16412  0.0  0.3  23440  3212 ?        S    21:53   0:00 nginx: worker process
nobody   16413  0.0  0.3  23440  3212 ?        S    21:53   0:00 nginx: worker process
root     16415  0.0  0.0 112676   984 pts/0    R+   21:55   0:00 grep --color=auto nginx
[root@hanfeng conf]# 
  1. 测试nginx,这里可以输入curl localhost 或者输入curl 127.0.0.1 得到的结果相同
[root@hanfeng conf]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@hanfeng conf]# 
  1. 测试解析php,新建一个1.php文件
[root@hanfeng conf]# vim /usr/local/nginx/html/1.php
写入
<?php
echo "this is nginx test page.";
[root@hanfeng conf]# curl localhost/1.php
this is nginx test page.[root@hanfeng conf]# 

转载于:https://my.oschina.net/u/3707314/blog/1600986

12.6 Nginx安装相关推荐

  1. 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx

    12.6 Nginx安装 [root@martin001 conf]# chkconfig --add nginx [root@martin001 conf]# chkconfig nginx on ...

  2. 12.6-12.9 Nginx安装,默认虚拟主机,用户认证,域名重定向

    12.6 Nginx安装 大纲 1 进入src目录,把nginx下载在此目录 #cd  /usr/local/src #wget http://nginx.org/download/nginx-1.8 ...

  3. 11-4 12 Nginx安装 默认虚拟主机 用户认证 域名重定向

    2019独角兽企业重金招聘Python工程师标准>>> 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向 扩展 ngin ...

  4. Nginx安装、默认虚拟主机、Nginx用户认证、Nginx域名重定向

    12.6 Nginx安装 安装包下载到/usr/local/src目录 [root@taoyuan ~]# cd /usr/local/src [root@taoyuan src]# wget htt ...

  5. 12.1 LNMP架构介绍 12.2 MySQL安装 12.3/12.4 PHP安装 12.5 Nginx介绍

    2019独角兽企业重金招聘Python工程师标准>>>  12.1 LNMP架构介绍 和LAMP不同的是,提供web服务的是Nginx 并且php是作为一个独立服务存在的,这个服务叫 ...

  6. Mac下PHP7.1+Nginx安装和配置

    https://blog.csdn.net/haiyanggeng/article/details/79186982 PHP:7.1.13 Nginx:1.12.2 1. 安装PHP # 添加源 br ...

  7. 12.1 LNMP架构介绍;12.2 MySQL安装;12.3-2.4 PHP安装(上下);12.5

    扩展: Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html apache和ng ...

  8. Nginx-1.12.2编译安装

    Nginx的概述 Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,第一个 ...

  9. Centos 6.0/ Nginx 安装与配置

    系统:Centos 6.0 下载nginx(nginx-1.2.4.tar.g)   http://nginx.org/ 下载pcre(pcre-8.31.tar.gz)    http://pcre ...

最新文章

  1. Linux操作系统文件系统基础知识详解
  2. [zz]Apache Thrift学习小记
  3. python 自动化-Python API 自动化实战详解(纯代码)
  4. Java举例include_Java StringUtils.getFilenameExtension方法代码示例
  5. Python编程语言学习:for循环实现对多个不同的DataFrame数据执行相同操作(可用于对分开的测试集、训练集实现执行相同逻辑任务)
  6. Hadoop 使用自动化脚本启动hdfs和yarn
  7. php建站静态,php网站如何生成静态
  8. Kaggle官网免费课程:从Python到机器学习,4小时学完一门,48小时掌握数据科学...
  9. 前端-requests-flask对应关系 file
  10. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,网页一直处于加载中,servlet+html+js+css项目难题解决
  11. 基于STM32单片机多功能电梯系统设计(论文原理图程序)
  12. Android-隐藏app图标以及隐式启动
  13. 信号处理--傅里叶变换的性质及常用信号的傅里叶变换
  14. H3C交换机关闭STP生成树协议的方法
  15. Facebook新研究:根据照片自动生成卡通头像
  16. DVI-A、DVI-D、DVI-I接口定义、DVI接口图和DVI接口标准介绍
  17. Tampermonkey的使用
  18. php拼车网源码,PHP拼车网源码 微信拼车源码 手机拼车源码 PC+微信双终端
  19. C语言求1到100的和
  20. 扬声器程序设计(微机原理实验四)

热门文章

  1. LottieJS动画的安装与使用
  2. 浅谈springboot三层架构
  3. 利用CnkiSpider包快速爬取知网文献信息
  4. 越来越吃香的BA职位,是什么回事?
  5. Python3爬虫1
  6. cmd 关闭系统进程
  7. 基于视觉的机器人抓取-综述
  8. python按钮居中_button按钮居中
  9. 千兆以太网一致性测试
  10. python樱花树画法图片_Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)...