CentOS 7 安装Nginx-1.9.2
2016-02-01 00:00
627 查看
CentOS 7 安装Nginx-1.9.2
1、安装必备工具:yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
说明:
pcre: 用来作地址重写的功能。
zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。
openssl:提供ssl加密协议。
2、新建一个系统级用户组和匿名用户,以及下面编译时使用
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
3、下载nginx
wget http://nginx.org/download/nginx-1.9.7.tar.gz
tar -zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7/
4、编译nginx
[root@localhost nginx-1.9.7]#
点击(此处)折叠或打开
./configure \
--prefix=/etc/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/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
[root@localhost nginx-1.9.7]# make -j4 && make install
[root@localhost nginx-1.9.7]# mkdir -p /var/cache/nginx/client_temp
[root@localhost nginx-1.9.7]# systemctl stop httpd.service
[root@localhost nginx-1.9.7]# nginx -c /etc/nginx/nginx.conf
5、Nginx 控制脚本
[root@localhost nginx-1.9.7]# gedit /usr/lib/systemd/system/nginx.service
点击(此处)折叠或打开
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP ${MAINPID}
ExecStop=/bin/kill -WINCH ${MAINPID}
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6、修改权限
[root@localhost nginx-1.9.7]# chmod +x /usr/lib/systemd/system/nginx.service
[root@localhost nginx-1.9.7]# systemctl enable nginx.service
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'
# 会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。
7、使用下面的指令来控制nginx
systemctl start nginx.service
systemctl reload nginx.service
systemctl restart nginx.service
systemctl stop nginx.service
8、查看日志
journalctl -f -u nginx.service
++++++++++++++++++++++++++++++++++
[root@localhost nginx]# gedit /etc/nginx/nginx.conf
点击(此处)折叠或打开
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
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;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~ \.cgi$ {
fastcgi_pass 127.0.0.1:8088;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;
include fastcgi_params;
}
#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;
#}
}
# 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;
# }
#}
}
相关文章推荐
- (Not OK) 在CentOS7—编译nginx—for—Android—Makefile
- CentOS7—Nginx—FastCGI 程序(C/C++)
- Centos7-64bit尝试编译最新版的nginx1.9.3+php7+mysql5.6.25
- Nginx的页面中文乱码解决方法
- Nginx基础入门之相关配置模板样例参考
- CentOS7编译安装nginx-1.8.1和编译参数
- Nginx基础入门之uptream负载均衡常用配置项说明
- Linux学习笔记之更新yum安装最新Nginx+Php
- tornado+nginx遇到的问题
- nginx做非80端口转发
- FreeBSD+nginx+php+fcgi配置步骤(…
- web服务器nginx和apache的对比分析
- nginx、apach、php、mysql编译参数
- 【转】Nginx+php-fpm+MySQL分离部署详解
- linux nginx环境搭建
- 504 Gateway Time-out
- Nginx服务器下配置使用索引目录的教程
- Nginx+Varnish
- 设置nginx禁止IP直接访问,只能通过指定的域名访问
- Samba & Nginx - Resource temporarily unavailable