热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CentOS7.3编译安装Nginx1.10.1

编译环境安装yum-ygccyum-ygcc++yum-ygcc-c++yum-yinstallwget下载安装文件并解压创建文件夹并进入mkdirsoft&&cdsoft下载

编译环境安装

yum -y gcc
yum -y gcc++
yum -y gcc-c++
yum -y install wget

下载安装文件并解压


> 创建文件夹并进入
mkdir soft && cd soft > 下载依赖文件pcre,openssl,zlib
wget -c http://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
wget -c https://www.openssl.org/source/openssl-1.0.2l.tar.gz
wget -c http://zlib.net/zlib-1.2.11.tar.gz
> 下载nginx
wget -c http://nginx.org/download/nginx-1.10.1.tar.gz
> 解压文件
tar -zxvf pcre-8.39.tar.gz
tar -zxvf openssl-1.0.2l.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf nginx-1.10.1.tar.gz

创建用户和目录


> 新建系统账号nginx
useradd -r nginx -s /sbin/nologin -M
> 新建nginx需要的目录
mkdir -p /var/tmp/nginx/{client_body,proxy,fastcgi,uwsgi,scgi}
> 递归改变目录所有者
chown -R nginx /var/tmp/nginx

编译nginx-1.10.1


cd ~/soft/nginx-1.10.1
./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre=../pcre-8.39 \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.0.2l \
--with-debug \
--http-client-body-temp-path=/var/tmp/nginx/client_body \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-stream
make && make install

编辑服务脚本文件


> 创建文件并打开服务脚本文件
vim /etc/init.d/nginx
> 编写脚本文件
#! /bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
#
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n "Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n "Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n "Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
;;
esac

配置nginx启动脚本


> 改变文件权限
chmod +x /etc/init.d/nginx
> 添加到系统服务
chkconfig --add nginx
> 设置系统为开机启动
chkconfig nginx on

启动nginx服务器


systemctl start nginx

启动服务状态


[root@localhost soft]# systemctl status nginx.service
● nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (running) since Tue 2017-06-13 11:47:44 EDT; 22s ago
Docs: man:systemd-sysv-generator(8)
Process: 40801 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
Main PID: 40808 (nginx)
Memory: 1.0M
CGroup: /system.slice/nginx.service
├─40808 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─40809 nginx: worker process
Jun 13 11:47:43 localhost.localdomain systemd[1]: Starting SYSV: Nginx is an HTTP(S) server,
HTTP(S) reverse proxy and IMAP/POP3 proxy server...
Jun 13 11:47:44 localhost.localdomain nginx[40801]: Starting nginx: [ OK ]
Jun 13 11:47:44 localhost.localdomain systemd[1]: Started SYSV: Nginx is an HTTP(S) server,
HTTP(S) reverse proxy and IMAP/POP3 proxy server.
[root@localhost soft]#

修改nginx配置文件


# 运行用户
#user nobody;
# 启动进程, 通常设置成和cpu的数据相等
worker_processes 1;
# 全局错误日志及PID文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
# 工作模式及连接数上限
events {

use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]";
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
server {
listen 80;
server_name www.nginx.dev;
#charset koi8-r;
access_log logs/nginx.dev.access.log main;
location / {
root /data/www/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/www/html;
}
location ~ ^/(images|Javascript|js|css|flash|media|static)/ {

expires 30d;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

CentOS7添加开放80TCP端口


> 加入开放端口到配置文件
firewall-cmd --zOne=public --add-port=80/tcp --permanent
--zOne=public 添加时区
--add-port=80/tcp 添加端口
--permanent 永久生效
> 加载防火墙新配置文件( 以 root 身份输入以下命令,重新加载防火墙,并不中断用户连接,即不丢失状态信息. )
firewall-cmd --reload

希望本文对你的工作和学习有所帮助

如果觉得还不错怎么感谢我呢? 妈呀! 点赞啊!

Good Luck! from warnerwu at 2017.06.24 PM


推荐阅读
  • centos6.8 下nginx1.10 安装 ... [详细]
  • centos安装Mysql的方法及步骤详解
    本文介绍了centos安装Mysql的两种方式:rpm方式和绿色方式安装,详细介绍了安装所需的软件包以及安装过程中的注意事项,包括检查是否安装成功的方法。通过本文,读者可以了解到在centos系统上如何正确安装Mysql。 ... [详细]
  • 现在比较流行使用静态网站生成器来搭建网站,博客产品着陆页微信转发页面等。但每次都需要对服务器进行配置,也是一个重复但繁琐的工作。使用DockerWeb,只需5分钟就能搭建一个基于D ... [详细]
  • 【技术分享】一个 ELF 蠕虫分析
    【技术分享】一个 ELF 蠕虫分析 ... [详细]
  • centos php部署到nginx 404_NodeJS项目部署到阿里云ECS服务器全程详解
    本文转载自:http:www.kovli.com20170919ecs-deploy作者:Kovli本文详细介绍如何部署NodeJS项目到阿里云ECS上, ... [详细]
  • 基于SSL的mysql服务器的主从架构实现说明:本文选用172.16.22.1作为主服务器,172.16.22.3作为从服务器从服务器的mysql软件版 ... [详细]
  • linux下编译安装lnmp
    2019独角兽企业重金招聘Python工程师标准#######################安装依赖#####################安装必要的包:y ... [详细]
  • linux clickhouse安装在指定目录_Centos8服务器指定目录安装配置Nginx
    1.安装前准备(1)检查是否安装过nginx(如果没有安装过可以无视)find-namenginx搜索nginx文件及其文件夹rm-rf【nginx配置地址文件及其文件夹】手动删除 ... [详细]
  • 本文介绍了在Linux下安装和配置Kafka的方法,包括安装JDK、下载和解压Kafka、配置Kafka的参数,以及配置Kafka的日志目录、服务器IP和日志存放路径等。同时还提供了单机配置部署的方法和zookeeper地址和端口的配置。通过实操成功的案例,帮助读者快速完成Kafka的安装和配置。 ... [详细]
  • tcpdump 4.5.1 crash 深入分析
    tcpdump 4.5.1 crash 深入分析 ... [详细]
  • 第四讲ApacheLAMP服务器基本配置Apache的编译安装从Apache的官方网站下载源码包:http:httpd.apache.orgdownload.cgi今 ... [详细]
  • charles3.11.1抓https包
    结论先行:用的是安卓测试机,没加固之前的生产环境的安装包,可以抓到https请求加固之后的包【也就是要上应用市场的包】,抓不到https请求电脑上的操作:1.安装证书【电脑上安装了 ... [详细]
  • VS用c语言连接mysql,c语言连接mysql完整演示
    #include#includeintmain(){MYSQL*conn;创建一个指向mysql数据类型的指针connmysql_init(NULL);mysql的初始化if(!c ... [详细]
  • 开发笔记:Squid代理服务
    本文由编程笔记#小编为大家整理,主要介绍了Squid代理服务相关的知识,希望对你有一定的参考价值。Squid服务基础缓存代理概述 ... [详细]
  • 本文是搭建的mariadb-10.0.17版本的下载地址:https:downloads.mariadb.orginterstitialmariadb-10.0.17sourcemariadb-10.0.17.tar.gzfromhtt ... [详细]
author-avatar
once
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有