今天在最新的centos7.2上安装nginx1.9,希望安装流程对你有所帮助,一定要查看对应centos的版本。

一、确认一下centos的版本

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

二、安装依赖包和开发工具:

yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33

成功返回:

Transaction Summary

================================================================================

Install 91 Packages (+45 Dependent packages)

Upgrade 9 Packages (+19 Dependent packages)

Total size: 202 M

Total download size: 178 M

三、清除系统中的httpd痕迹

yum remove httpd

rm -rvf /etc/httpd

rm /usr/bin/pod2man

四、创建www用户和用户组:

groupadd www

useradd -s /sbin/nologin -g www www

五、解压nginx模块包:

tar zxvf zlib-1.2.8.tar.gz -C /usr/src

tar zxvf pcre-8.12.tar.gz -C /usr/src

tar zxvf openssl-1.0.1.tar.gz -C /usr/src

六、解压、配置、编译、安装nginx1.9:

tar zxvf nginx-1.9.0.tar.gz -C /usr/src/

cd /usr/src/nginx-1.9.0/

./configure --prefix=/usr/local/nginx \

--user=www \

--group=www \

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

--conf-path=/usr/local/nginx/conf/nginx.conf \

--error-log-path=/home/www/log/error.log \

--http-log-path=/home/www/log/access.log \

--pid-path=/home/www/pid/nginx.pid \

--lock-path=/home/www/pid/nginx.lock \

--with-mail \

--with-file-aio \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_dav_module \

--with-http_sub_module \

--with-http_spdy_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_stub_status_module \

--with-zlib=/usr/src/zlib-1.2.8 \

--with-pcre=/usr/src/pcre-8.12 \

--with-openssl=/usr/src/openssl-1.0.1 \

--without-select_module \

--without-poll_module \

--http-client-body-temp-path=/tmp/clientbody \

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

--http-fastcgi-temp-path=/tmp/fastcgi \

--http-uwsgi-temp-path=/tmp/uwsgi \

--http-scgi-temp-path=/tmp/scgi

make

make install

七、编辑nginx.conf配置文件:

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak

ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx.conf

vim /etc/nginx.conf

user www www;

worker_processes auto;

pid /home/www/pid/nginx.pid;

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

multi_accept on;

}

http

{

include mime.types;

default_type application/octet-stream;

charset UTF-8;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;

client_body_buffer_size 128k;

sendfile on;

tcp_nopush on;

keepalive_timeout 45;

server_tokens off;

tcp_nodelay on;

# Proxy

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header REMOTE-HOST $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Fastcgi

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 256k;

# Gzip Compression

gzip on;

gzip_buffers 16 8k;

gzip_comp_level 2;

gzip_http_version 1.1;

gzip_min_length 256;

gzip_proxied any;

gzip_vary on;

gzip_types

# MIME Type

text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml

text/javascript application/javascript application/x-javascript

text/x-json application/json application/x-web-app-manifest+json

text/css text/plain text/x-component

font/opentype application/x-font-ttf application/vnd.ms-fontobject

image/x-icon;

gzip_disable "msie6";

# Cache

open_file_cache max=51200 inactive=20s;

open_file_cache_valid 30s;

open_file_cache_min_uses 1;

open_file_cache_errors on;

# Log Format

log_format access '[$time_iso8601] "$remote_addr" "$http_x_forwarded_for"'

'"$request" "$request_body" "$http_cookie"'

'"$upstream_addr" "$upstream_status"'

'"$http_referer" "$status"'

'"$body_bytes_sent" "$http_user_agent"';

################################################## default ##################################################

server

{

listen 80 default;

server_name 127.0.0.1;

access_log /home/www/log/access.log access;

error_log /home/www/log/error.log error;

root /home/www/html/;

index index.html index.htm index.php;

location ~ [^/]\.php(/|$)

{

fastcgi_pass unix:/dev/shm/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

}

location /nginx_status

{

stub_status on;

access_log off;

allow 127.0.0.1;

deny all;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$

{

expires 30d;

access_log off;

}

location ~ .*\.(js|css)?$

{

expires 7d;

access_log off;

}

if (!-e $request_filename)

{

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

}

################################################## vhost ##################################################

include vhost/*.conf;

}

复制代码

八、创建nginx相关目录,并修改权限:

mkdir -p /home/www/html

chown -R www:www /home/www/

九、测试启动nginx服务:

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

nginx -t

nginx -c /usr/local/nginx/conf/nginx.conf

ps -aux | grep nginx

netstat -anptu | grep 80

十、编写nginx启动脚本:

vim /etc/init.d/nginx

#!/bin/sh

# chkconfig: 2345 80 20

# Description: Start and Stop Nginx

# Provides: nginx

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=nginx

NGINX_BIN=/usr/local/nginx/sbin/$NAME

CONFIGFILE=/usr/local/nginx/conf/$NAME.conf

PIDFILE=/home/www/pid/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

case "$1" in

start)

echo -n "Starting $NAME... "

if netstat -tnpl | grep -q nginx;then

echo "$NAME (pid `pidof $NAME`) already running."

exit 1

fi

$NGINX_BIN -c $CONFIGFILE

if [ "$?" != 0 ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

stop)

echo -n "Stoping $NAME... "

if ! netstat -tnpl | grep -q nginx; then

echo "$NAME is not running."

exit 1

fi

$NGINX_BIN -s stop

if [ "$?" != 0 ] ; then

echo " failed. Use force-quit"

exit 1

else

echo " done"

fi

;;

status)

if netstat -tnpl | grep -q nginx; then

PID=`pidof nginx`

echo "$NAME (pid $PID) is running..."

else

echo "$NAME is stopped"

exit 0

fi

;;

force-quit)

echo -n "Terminating $NAME... "

if ! netstat -tnpl | grep -q nginx; then

echo "$NAME is not running."

exit 1

fi

kill `pidof $NAME`

if [ "$?" != 0 ] ; then

echo " failed"

exit 1

else

echo " done"

fi

;;

restart)

$SCRIPTNAME stop

sleep 1

$SCRIPTNAME start

;;

reload)

echo -n "Reload service $NAME... "

if netstat -tnpl | grep -q nginx; then

$NGINX_BIN -s reload

echo " done"

else

echo "$NAME is not running, can't reload."

exit 1

fi

;;

configtest)

echo -n "Test $NAME configure files... "

$NGINX_BIN -t

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"

exit 1

;;

esac

十一、添加nginx系统服务:

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

chkconfig --add nginx

chkconfig --level 2345 nginx on

chkconfig --list | grep nginx

十二、重新启动nginx服务:

service nginx restart

ps -aux | grep nginx

netstat -anptu | grep 80

十三、测试:

vim /home/www/html/index.html

This is test nginx!!!

nginx server test is ok!!!

chown www:www /home/www/html/index.html

十四、防火墙开启80端口:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

linux安装nginx1.9,CentOS7.2安装Nginx 1.9相关推荐

  1. linux最小安装桌面,Linux工作环境:CentOS7最小安装+Xfce桌面环境

    ref: https://blog.csdn.net/smstong/article/details/44802989 3.1 执行CentOS7 最小安装 去官网下载CentOS-7.0-1406- ...

  2. linux centos安装wine qq,centos7下安装wine+QQ成功实例

    ​1.添加一个第三方yum源EPEL,以利用该源来进行yum安装wine,而不用自己下源码来编译,自己编译时间长,且需安装很多包,比较麻烦: 具体做法:​/etc/yum.repo.d下新建一个EPE ...

  3. 【rabbitmq安装教程】centos7下安装rabbitMQ

    命令: 1.先安装Erlang cd usr/local/src/ wget http://www.rabbitmq.com/releases/erlang/erlang-19.0.4-1.el7.c ...

  4. 在一台win10系统的电脑里安装虚拟机运行CentOS7并实现nginx反向代理从而用域名访问本机的微服务项目

    在虚拟机里的CentOS7安装配置nginx,之前需要一些依赖库作为编译安装的条件,具体作用和命令详情跳转我之前的博客. 安装并使用VMware-workstation-full-15.5.0安装Ce ...

  5. linux yum安装svn版本号,CentOS7 yum安装svn服务

    svn服务器搭建 1.yum install subversion 2.输入rpm -ql subversion查看安装位置 3.创建svn版本库目录 mkdir -p /var/svn/svnrep ...

  6. linux安装vsftp教程,CentOS7 vsftp 安装与配置(视频教程)

    (双击全屏播放) 1.安装vsftpd yum install -y vsftpd 2.编辑ftp配置文件 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO ...

  7. docker安装nginx1.20.2并配置nginx.conf

    一.docker拉取nginx镜像 docker pull nginx:1.20.2 二.创建映射容器的文件目录 # 创建配置文件目录 mkdir -p /mydata/nginx/conf/ mkd ...

  8. centos php安装redis扩展,Centos7编译安装redis、php安装phpredis扩展

    解压 进入 make: # tar zxvf redis-4.0.9.tar.gz # cd redis-4.0.9/ # make # cd src # make install 为了方便管理,将R ...

  9. 【安装MongoDB】CentOS7 下安装NodeJs+Express+MongoDB+Redis

    MongoDB,V3.2版本,官网说的很详细,见链接:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 1.创建 ...

最新文章

  1. C++面向对象模型初探
  2. 【Lucene4.8教程之中的一个】使用Lucene4.8进行索引及搜索的基本操作
  3. python将文本中的数据处理成图像(matplotlib)
  4. 基于Java+SpringBoot+vue+element实现家具购物销售网站详细设计和实现
  5. AngularJS----服务,表单,模块
  6. Spark交互式工具spark-shell
  7. Delphi7 JSON文件生成
  8. 秒变金庸风 | NLP文本风格迁移
  9. C专家编程--随记(二)
  10. 史上最全的iOS开源项目分类汇总没有之一
  11. How long have you been studying English(第一节)
  12. vue中组件之间调用方法——子组件调用父组件的方法 父组件调用子组件的方法
  13. 基于Hive的搜狗搜索日志与结果Python可视化设计
  14. 安卓手机变Win10桌面APP
  15. ubuntu18.04 输入法的配置
  16. ​word分节符与分页符的区别与用法
  17. python创建子目录并在子目录下创建文件
  18. 11_张孝祥_多线程_线程锁技术
  19. PartTime_网址_国外
  20. 游戏里面的3D模型是怎么制作的?有哪些特点?

热门文章

  1. layui父页面调用子页面的渲染_layui的iframe父子操作方法
  2. 借贷记账法下的账户对应关系_笔记整理,会计复式记账法内容及实例
  3. 鸿蒙开发者有多少,鸿蒙开发者beta版本申请通过的过来人有几句话要说
  4. linuxmint安装开发工具_vscode如何安装在Linuxmint系统_编程开发工具
  5. mongdb 建立了索引唯一性还能重复插入?_「数据库系列」Postgres性能调优——Index...
  6. 深度学习之基于CNN实现天气识别
  7. Quadratic equation(二次剩余)2019牛客多校第九场
  8. Sklearn 损失函数如何应用到_机器学习大牛最常用的5个回归损失函数,你知道几个?...
  9. 鸿蒙系统有无隐私空间,华为鸿蒙OS系统有隐私空间功能吗 华为p40使用鸿蒙系统体验评测...
  10. 计算机体系结构--第一章1----体系结构的分类