当前位置:首页一些小笔记NGINX编译安装及主机配置分离

NGINX编译安装及主机配置分离

编译安装

安装依赖

yum -y install openssl openssl-devel pcre pcre-devel gcc gcc-c++

下载软件包

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

创建用户

useradd nginx -s /sbin/nologin -M解压tar

zxvf nginx-1.6.3.tar.gz


cd nginx-1.6.3


安装
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install


启动前检查配置文件语法:
/usr/local/nginx/sbin/nginx -t
# ok // succeddful

启动服务

/usr/local/nginx/sbin/nginx

重启服务

/usr/local/nginx/sbin/nginx -s reload

查询端口是否启动成功

lsof -I 80
netstat -lnt |grep 80
pkil nginx 结束进程
userdel nginx 永久删除用户

查看nginx参数

/usr/local/nginx/sbin/nginx -V

关闭防火墙
临时关闭
setenforce 0
永久关闭

grep SELINUX=disable /etc/selinux/config
iptable
/etc/init.d/iptables stop
chkconfig iptables off 禁止开机自启

日志文件地址


/usr/local/nginx/log

虚拟主机配置

默认配置地址:


/usr/local/nginx/conf/nginx.conf
NGINX编译安装及主机配置分离

创建域名为baidu.com的虚拟主机

worker_processes  1;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
server {
listen       80;
server_name  localhost;
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  badiu.com;      #绑定域名
location / {
root   html/baidu;         #目录设置为/baidu
index  index.html index.htm;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
}
}

在baidu目录里创建index.html

echo baidu.com > baidu/index.html

修改hosts解析,将baidu.com指向本地ip

Vim /etc/hosts

加入

127.0.0.1 baidu.com

测试nginx配置文件是否正确

/usr/local/nginx/sbin/nginx -t

重启

/usr/local/nginx/sbin/nginx -s reload

使用curl测试是否成功


Curl baidu.com

配置分离

修改nginx配置文件

vim /usr/local/nginx/conf/ nginx.conf

将server部分移除,并加入include

worker_processes  1;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
include vhost/*.conf;       #是配置文件分离,存至vhost目录已conf结尾的文件
}

创建vhost文件(不固定,以上方填写的路径为准)

mkdir /usr/local/nginx/conf/vhost


在vhost文件中创建上篇文章中的两个站点的配置文件
vim default.conf
server {
listen       80;
server_name  localhost;
location / {
root   html;
index  index.html index.htm;
}
error_page  404              /404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
}

vim baidu.conf

server {
listen       81;
server_name  baidu.com;
location / {
root   html/baidu;
index  index.html index.htm;
}
error_page  404              /404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
}
nginx模块
--with-http_ssl_module #启用ngx_http_ssl_module
--with-http_realip_module #启用 ngx_http_realip_module
--with-http_addition_module #启用 ngx_http_addition_module
--with-http_sub_module #启用 ngx_http_sub_module
--with-http_dav_module #启用 ngx_http_dav_module
--with-http_flv_module #启用 ngx_http_flv_module
--with-http_stub_status_module #启用 "server status" 页
--without-http_charset_module #禁用 ngx_http_charset_module
--without-http_gzip_module #禁用 ngx_http_gzip_module. 如果启用,需要 zlib 。
--without-http_ssi_module #禁用 ngx_http_ssi_module
--without-http_userid_module #禁用 ngx_http_userid_module
--without-http_access_module #禁用 ngx_http_access_module
--without-http_auth_basic_module #禁用 ngx_http_auth_basic_module
--without-http_autoindex_module #禁用 ngx_http_autoindex_module
--without-http_geo_module #禁用 ngx_http_geo_module
--without-http_map_module #禁用 ngx_http_map_module
--without-http_referer_module #禁用 ngx_http_referer_module
--without-http_rewrite_module #禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。
--without-http_proxy_module #禁用 ngx_http_proxy_module
--without-http_fastcgi_module #禁用 ngx_http_fastcgi_module
--without-http_memcached_module #禁用 ngx_http_memcached_module
--without-http_limit_zone_module #禁用 ngx_http_limit_zone_module
--without-http_empty_gif_module #禁用 ngx_http_empty_gif_module
--without-http_browser_module #禁用 ngx_http_browser_module
--without-http_upstream_ip_hash_module #禁用 ngx_http_upstream_ip_hash_module
--with-http_perl_module - #启用 ngx_http_perl_module
--with-perl_modules_path=PATH #指定 perl 模块的路径
--with-perl=PATH #指定 perl 执行文件的路径
--http-log-path=PATH #Set path to the http access log
--http-client-body-temp-path=PATH #Set path to the http client request body temporary files
--http-proxy-temp-path=PATH #Set path to the http proxy temporary files
--http-fastcgi-temp-path=PATH #Set path to the http fastcgi temporary files
--without-http #禁用 HTTP server
--with-mail #启用 IMAP4/POP3/SMTP 代理模块
--with-mail_ssl_module #启用 ngx_mail_ssl_module
--with-cc=PATH #指定 C 编译器的路径
--with-cpp=PATH #指定 C 预处理器的路径
--with-cc-opt=OPTIONS #
--with-ld-opt=OPTIONS #Additional parameters passed to the linker. With the use of the system library PCRE in FreeBSD, it is necessary to indicate --with-ld-opt="-L /usr/local/lib".
--with-cpu-opt=CPU #为特定的CPU编译,有效的值包括:pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
--without-pcre #禁止PCRE库的使用。同时也会禁止 HTTP rewrite 模块。在 "location" 配置指令中的正则表达式也需要 PCRE 。
--with-pcre=DIR #指定 PCRE 库的源代码的路径。
--with-pcre-opt=OPTIONS #设置PCRE的额外编译选项。
--with-md5=DIR #使用MD5汇编源码。
--with-md5-opt=OPTIONS #Set additional options for md5 building.
--with-md5-asm #Use md5 assembler sources.
--with-sha1=DIR #Set path to sha1 library sources.
--with-sha1-opt=OPTIONS #Set additional options for sha1 building.
--with-sha1-asm #Use sha1 assembler sources.
--with-zlib=DIR #Set path to zlib library sources.
--with-zlib-opt=OPTIONS #Set additional options for zlib building.
--with-zlib-asm=CPU #Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro
--with-openssl=DIR #Set path to OpenSSL library sources
--with-openssl-opt=OPTIONS #Set additional options for OpenSSL building
--with-debug #启用调试日志
--add-module=PATH #Add in a third-party module found in directory PATH

给TA打赏
共{{data.count}}人
人已打赏
一些小笔记

实用网站分享:全栈开发可能需要用到的网站

2018-5-15 17:48:07

一些小笔记

PHP利用Apache、Nginx的特性实现免杀Webshell

2019-2-14 1:07:28

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索

Warning: Undefined array key "avatar" in /www/wwwroot/blog.xzbzq.com/wp-content/themes/b2Jitheme/jitheme_functions.php on line 397

Warning: Undefined array key "name" in /www/wwwroot/blog.xzbzq.com/wp-content/themes/b2Jitheme/jitheme_functions.php on line 397

Warning: Undefined array key "avatar" in /www/wwwroot/blog.xzbzq.com/wp-content/themes/b2Jitheme/jitheme_functions.php on line 397

Warning: Undefined array key "name" in /www/wwwroot/blog.xzbzq.com/wp-content/themes/b2Jitheme/jitheme_functions.php on line 397
  • 纯七发布圈子单身三年现状
  • 纯七发布圈子单身三年现状
  • 对文章腾讯音乐人认证教程发布评论!