欠自己的nginx部署文档

本文详细介绍Nginx从下载安装到配置运行的全过程,并解决常见错误,包括依赖库安装、端口冲突处理及基本服务器配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值