Nginx配置部署
1.下载nginx包
mkdir /usr/local/nginx
cd /usr/local/nginx
wget http://nginx.org/download/nginx-1.5.9.tar.gz
2.编译安装
tar -zvxf nginx-1.5.9.tar.gz
cd nginx-1.5.9
./configure --prefix=/usr/local/nginx
#报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决办法:
*下载安装包
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
*编译安装
tar -zvxf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make && make install
2.1继续编译安装
cd /usr/local/nginx/nginx-1.5.9
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/nginx/pcre2-10.21
#报错
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
解决办法:
*下载安装包
wget https://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
*编译安装
tar -zvxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
2.2继续编译安装
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/nginx/pcre-8.38 --with-zlib=/usr/local/nginx/zlib-1.2.11
make && make install
3.安装成功后启动
#启动进程
/usr/local/nginx/sbin/nginx
#报错
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
*解决办法:
ps aux|grep apache
出现以下列表
root 30697 0.0 0.0 11740 932 pts/0 S+ 12:32 0:00 grep --color=auto nginx
root@iZ94hbx8k2tZ:/usr/local/nginx# ps aux|grep apache
www-data 1957 0.0 0.6 330636 13860 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 3586 0.0 0.6 330636 13876 ? S Aug01 0:00 /usr/sbin/apache2 -k start
www-data 14632 0.0 0.6 330636 13912 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 23349 0.0 0.6 330636 13912 ? S Aug01 0:00 /usr/sbin/apache2 -k start
root 25241 0.0 1.2 330136 24732 ? Ss 2016 19:29 /usr/sbin/apache2 -k start
root 30699 0.0 0.0 11740 932 pts/0 S+ 12:32 0:00 grep --color=auto apache
www-data 31914 0.0 0.6 330636 13864 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31915 0.0 0.6 330636 13904 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31916 0.0 0.6 330636 13912 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31917 0.0 0.6 330636 13916 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31918 0.0 0.6 330636 13908 ? S Jul31 0:00 /usr/sbin/apache2 -k start
原因找到了自带的Apache进程启动了,占用了80端口,kill了apache进程树
pkill apache
再次执行
/usr/local/nginx/sbin/nginx
启动成功
4.nginx服务器配置
#打开/usr/local/nginx/conf/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;
access_log logs/access.log ;
# location / {
# root /var/www/html;
# index index.html index.htm index.php;
# }
#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 /var/www/html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# 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;
# }
#}
include /usr/local/nginx/conf/vhost/*;
}
#创建一个文件夹
mkdir vhost
cd vhost
cp ../nginx.conf.default new.conf
vim new.conf
server {
listen 80;
server_name hao123.local;
root /var/www/navigator;
#charset koi8-r;
index index.html index.htm index.php;
#access_log logs/host.access.log main;
access_log logs/access.log ;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
# location / {
# root /var/www/html;
# index index.html index.htm index.php;
# }
#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 /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
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;
#}
}
5.重启nginx
/usr/local/nginx/sbin/nginx -s reload
1.下载nginx包
mkdir /usr/local/nginx
cd /usr/local/nginx
wget http://nginx.org/download/nginx-1.5.9.tar.gz
2.编译安装
tar -zvxf nginx-1.5.9.tar.gz
cd nginx-1.5.9
./configure --prefix=/usr/local/nginx
#报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决办法:
*下载安装包
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
*编译安装
tar -zvxf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make && make install
2.1继续编译安装
cd /usr/local/nginx/nginx-1.5.9
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/nginx/pcre2-10.21
#报错
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
解决办法:
*下载安装包
wget https://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
*编译安装
tar -zvxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
2.2继续编译安装
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/nginx/pcre-8.38 --with-zlib=/usr/local/nginx/zlib-1.2.11
make && make install
3.安装成功后启动
#启动进程
/usr/local/nginx/sbin/nginx
#报错
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
*解决办法:
ps aux|grep apache
出现以下列表
root 30697 0.0 0.0 11740 932 pts/0 S+ 12:32 0:00 grep --color=auto nginx
root@iZ94hbx8k2tZ:/usr/local/nginx# ps aux|grep apache
www-data 1957 0.0 0.6 330636 13860 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 3586 0.0 0.6 330636 13876 ? S Aug01 0:00 /usr/sbin/apache2 -k start
www-data 14632 0.0 0.6 330636 13912 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 23349 0.0 0.6 330636 13912 ? S Aug01 0:00 /usr/sbin/apache2 -k start
root 25241 0.0 1.2 330136 24732 ? Ss 2016 19:29 /usr/sbin/apache2 -k start
root 30699 0.0 0.0 11740 932 pts/0 S+ 12:32 0:00 grep --color=auto apache
www-data 31914 0.0 0.6 330636 13864 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31915 0.0 0.6 330636 13904 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31916 0.0 0.6 330636 13912 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31917 0.0 0.6 330636 13916 ? S Jul31 0:00 /usr/sbin/apache2 -k start
www-data 31918 0.0 0.6 330636 13908 ? S Jul31 0:00 /usr/sbin/apache2 -k start
原因找到了自带的Apache进程启动了,占用了80端口,kill了apache进程树
pkill apache
再次执行
/usr/local/nginx/sbin/nginx
启动成功
4.nginx服务器配置
#打开/usr/local/nginx/conf/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;
access_log logs/access.log ;
# location / {
# root /var/www/html;
# index index.html index.htm index.php;
# }
#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 /var/www/html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# 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;
# }
#}
include /usr/local/nginx/conf/vhost/*;
}
#创建一个文件夹
mkdir vhost
cd vhost
cp ../nginx.conf.default new.conf
vim new.conf
server {
listen 80;
server_name hao123.local;
root /var/www/navigator;
#charset koi8-r;
index index.html index.htm index.php;
#access_log logs/host.access.log main;
access_log logs/access.log ;
location / {
try_files $uri $uri/ /index.php$is_args$query_string;
}
# location / {
# root /var/www/html;
# index index.html index.htm index.php;
# }
#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 /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
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;
#}
}
5.重启nginx
/usr/local/nginx/sbin/nginx -s reload