nginx 源码安装

安装nginx

安装pcre库是为了让nginx支持具备URI重写功能的rewrite模块

[[email protected] ~]# yum install pcre pcre-devel -y
[[email protected] ~]# rpm -qa  pcre pcre-devel

安装nginx 依赖的包 openssl-devel

[[email protected] ~]# yum install openssl openssl-devel
[[email protected] ~]# rpm -qa openssl openssl-devel

下载nginx源码包

[[email protected] tools]# wget -q http://nginx.org/download/nginx-1.9.2.tar.gz 

解压

[[email protected] nginx-1.9.2]# tar xf nginx-1.9.2.tar.gz
[[email protected] nginx-1.9.2]# cd nginx-1.9.2

配置文件

[[email protected] nginx-1.9.2]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.9.2/ --with-http_stub_status_module --with-http_ssl_module

安装

[[email protected] nginx-1.9.2]# make
[[email protected] nginx-1.9.2]# make install

创建软连接

[[email protected] nginx-1.9.2]# ln -s /application/nginx-1.9.2/ /application/nginx
[[email protected] nginx-1.9.2]# ls -l /application/nginx
lrwxrwxrwx 1 root root 25 Jan  7 03:16 /application/nginx -> /application/nginx-1.9.2/

检测nginx 配置文件知否正确

[[email protected] nginx-1.9.2]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.9.2//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.9.2//conf/nginx.conf test is successful

启动nginx

[[email protected] nginx-1.9.2]# /application/nginx/sbin/nginx 

查看nginx服务对应的端口是否成功启动

[[email protected] nginx-1.9.2]# lsof -i :80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   3620  root    6u  IPv4  27305      0t0  TCP *:http (LISTEN)
nginx   3621 nginx    6u  IPv4  27305      0t0  TCP *:http (LISTEN)

在防火墙上开端口

#查看防火墙上已经开启的端口`
[[email protected] nginx]# firewall-cmd --zone=public --list-port
#在防火墙上永久开启80端口
[[email protected] nginx]# firewall-cmd --zone=public --add-port=80/tcp --permanent
#重新载入
[[email protected] nginx]# firewall-cmd --reload

查看nginx 的目录结构

[[email protected] /]# tree /application/nginx/
/application/nginx/
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   └── index.html
├── logs
│   ├── access.log
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp

nginx配置虚拟主机

编辑Nginx的配置文件

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;

    #gzip  on;

    server {
    #nginx 默认监听的端口
        listen       80;
    #配置的虚拟主机的域名(测试环境中是自定义的)
        server_name  www.one.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        #新配置的虚拟主机所在根目录
            root   html/www;
            index  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   html;
        }

        # 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  /scripts$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;
        #}

    }
    ....
  }

修改完了配置文件,我们知道虚拟主机的关键部分是server{}括号中内容

根据配置的虚拟主机的根目录,创建站点目录和文件,因为Nginx编译安装的时候默认的站定目录是html,所以在改目录下创建

[[email protected] conf]# mkdir ../html/www -p
[[email protected] conf]# echo "http://www.one.com" > ../html/www/index.html
[[email protected] conf]# cat ../html/www/index.html
http://www.one.com

重新加载配置文件

  • 检查Nginx配置文件语法是否正确

    [[email protected] conf]# ../sbin/nginx -t
    nginx: the configuration file /application/nginx-1.9.2//conf/nginx.conf syntax is ok
    nginx: configuration file /application/nginx-1.9.2//conf/nginx.conf test is successful
  • 重新加载配置文件
    [[email protected] conf]# ../sbin/nginx -s reload
  • 检查Nginx重启加载后的情况
    [[email protected] conf]# ps -ef|grep nginx
    root      10820      1  0 08:54 ?        00:00:00 nginx: master process /application/nginx/sbin/nginx
    nginx     11152  10820  0 09:54 ?        00:00:00 nginx: worker process
    root      11154  11088  0 09:54 pts/1    00:00:00 grep --color=auto nginx
  • 本机的hosts文件解析(不是必须这样做) 和访问测试
    [[email protected] conf]# echo "192.168.85.129 www.one.com" >>/etc/hosts
    [[email protected] conf]# tail /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.85.130 www.one.com
    [[email protected] conf]# curl www.one.com
    http://www.one.com          #本地测试成功

原文地址:https://www.cnblogs.com/gongzhifan/p/8647533.html

时间: 2024-07-29 07:46:21

nginx 源码安装的相关文章

Nginx源码安装及调优配置(转)

导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优化 [[email protected] ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz [[email protected] ~]# tar xvf nginx-1.10.1.tar.gz -C /usr/local/src/ [[em

LAMP环境部署:Apache源码安装+MySQL二进制安装+PHP源码安装+Nginx源码安装

Apache 版本:2.2.27 MySQL 版本:5.5.54-linux2.6-x86_64PHP 版本:5.3.27一.源码安装Apache1.首先安装上传工具2.上传LAMP环境所需安装包3.解压所有安装包4.安装Apache依赖包5.创建安装目录6.配置安装文件./configure \ #./configure 是用来生成Makefile文件用于编译安装 --prefix=/application/apache-2.2.27 \ #指定安装目录--enable-deflate \ #

nginx 源码安装openssl修复Heartbleed漏洞

如果你的nginx使用的是动态的openssl库,直接升级openssl,如果你的nginx使用的是静态的openssl库,那就要重新编译安装nginx. PHP编译修复 1. nginx使用的是动态的openssl库,直接升级openssl    1.1 源码安装openssl1.0.1g版本        先下载openssl 1.0.1g版本,命令如下:            #wget  -c    https://www.openssl.org/source/openssl-1.0.1

nginx 源码安装以及后续升级https

事情的来源是,公司要将网站从http升级到https,由于历史遗留原因,才发现现有的nginx是通过源码安装的,并没有安装ssl模块,需要现安装sll模块,这个nginx是整个公司最前端的一个代理,涉及到很多部门,因为之前没有操作过,还是小心点为妙,下面是在虚拟机上演示的. 1,先安装后面所需的一些包 yum install gcc-c++ yum install pcre pcre-devel yum install zlib zlib-devel yum install openssl op

NGINX源码安装配置详解(./configure),最全解析

NGINX ./configure详解 在"./configure"配置中,"--with"表示启用模块,也就是说这些模块在编译时不会自动构建"--without"表示禁用模块,也就是说这些模块在编译时会自动构建,若你想Nginx轻量级运行,可以去除一些不必要的模块. [[email protected] nginx-1.14.0]# ./configure --help => 查看安装配置项 --help 打印帮助信息. --prefix

nginx源码安装

1.安装开发包 # yum install -y pcre-devel openssl-devel 2.解压源码包并编辑文件隐藏nginx版本 # tar zxvf nginx-1.8.0.tar.gz #  cd nginx-1.8.0 #  vim auto/cc/gcc #CFLAGS="$CFLAGS -g"               #注释掉这行,去掉debug模式编译,编译以后程序只有几百k # vim src/core/nginx.h #define NGINX_VER

nginx源码安装(CentOS版)

准备工作: 1) 配好网易yum源 登录此网站(http://mirrors.163.com/.help/centos.html),下载相应版本的yum源至服务器的/etc/yum.repos.d/目录下,然后按照此步骤进行操作,即可完成网易yum源的配置准备. 2) 安装make/gcc/zlib等安装包 yum install -y gcc automake autoconf libtool make yum install -y gcc gcc-c++ 开始: 1) 选定源码目录 cd /

Centos下Nginx源码安装与配置并附shell编程实现自动化安装

一.首先安装必要的库 nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库.选定/usr/local为安装目录,以下具体版本号根据实际改变. 1.安装PCRE库 $ cd /usr/local/ $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz $ tar -zxvf pcre-8.36.tar.gz $ cd pcre-8.3

nginx源码安装-及lnmp搭建 phpmyadmin

1.下载源码编译安装nginx wget http://nginx.org/download/nginx-1.17.1.tar.gztar -xvf nginx-1.17.1.tar.gzyum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel #安装编译环境./configure #运行内部的配置脚本make && make install #编译安装安装完成 cd 到 cd /usr/local/