安装Nginx网络HTTP服务器(Linux) (2015-01-23)
来源:互联网 发布:怎么查淘宝店地址 编辑:程序博客网 时间:2024/05/06 03:51
第一步:安装依赖库
CentOS用这个
yum install make gcc pcre-devel zlib-devel openssl-devel git bison wget
Ubuntu用这个
sudo apt-get install gcc libpcre++-dev libssl-dev make git
第二步:下载所需nginx的扩展源码
mkdir -p /home/git/codecd /home/git/codegit clone https://github.com/yaoweibin/ngx_http_substitutions_filter_modulegit clone https://github.com/agentzh/sregexgit clone https://github.com/agentzh/replace-filter-nginx-module
第三步:安装sregex
cd /home/git/code/sregexmakemake install
第四步:到www.nginx.org官方下载最新稳定版
mkdir ~/downcd ~/downwget http://nginx.org/download/nginx-1.8.0.tar.gztar zxvf nginx-1.6.2.tar.gz
第五步:编译安装
cd ~/down/nginx-1.6.2./configure \--with-http_stub_status_module \--with-http_ssl_module \--with-http_spdy_module \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-ipv6 \--add-module=/home/git/code/ngx_http_substitutions_filter_module \--add-module=/home/git/code/replace-filter-nginx-module
执行编译安装
makemake install
第六步:查看编译相关信息
/usr/local/nginx/sbin/nginx -V
如果看到下面的提示就对了
nginx version: nginx/1.6.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)TLS SNI support enabledconfigure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-ipv6 --add-module=/home/git/ngx_http_substitutions_filter_module --add-module=/home/git/replace-filter-nginx-module
第七步:启动与检查
当你执行下面语句时,没有任何返回,说明运行成功。
/usr/local/nginx/sbin/nginx
确定是否运行成功
netstat -anp |grep 80
如果结果中存在
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 712/nginx
说明成功了
再来看看712/nginx的具体路径
ps x |grep 712
如果结果是
712 ? Ss 0:00 nginx: master process /usr/local/nginx/sbin/nginx
可以看到路径/usr/local/nginx/sbin/nginx说明成功了
最后将
/usr/local/nginx/sbin/nginx
写入到
/etc/rc.local
让系统开机就自动启动nginx
最后说一些可能会出现的问题
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libsregex.so.0: cannot open shared object file: No such file or directory
对于上面这种问题,可以用下面方法解决
ldd /usr/local/nginx/sbin/nginx
确定问题后,如果是32位系统执行
ln -s /usr/local/lib/libsregex.so.0 /lib
如果是64位系统,执行
ln -s /usr/local/lib/libsregex.so.0 /lib64
关于配置PHP方面的
请编辑下面文件(推荐vi或vim)
/usr/local/nginx/conf/nginx.conf
1:找到下面一段文字,大概在65行(vi/vim编辑器的可以使用:65到达)
#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; #}
将每一行前面的#符号都去掉
2:将其中的
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
改成
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3:保存后,重新载入nginx配置文件
/usr/local/nginx/sbin/nginx -t/usr/local/nginx/sbin/nginx -s reload
4:创建phpinfo.php测试文件
/usr/local/nginx/html/phpinfo.php
内容为
<?phpphpinfo();
5:运行php文件测试
http://127.0.0.1/phpinfo.php
请将127.0.0.1换成你服务器的IP地址,并在浏览器里打开查看。
配置参考
worker_processes 1;pid logs/nginx.pid;events{ worker_connections 1024;}http{ access_log off; include mime.types; sendfile on; client_body_temp_path temp/client_body_temp; fastcgi_temp_path temp/fastcgi_temp; scgi_temp_path temp/scgi_temp; uwsgi_temp_path temp/uwsgi_temp; proxy_temp_path temp/proxy_temp; server{ listen 0.0.0.0:80; server_name www.baidu.com; proxy_set_header Host www.baidu.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://www.baidu.com; } } server{ listen 0.0.0.0:80 default; root html; }}
0 0
- 安装Nginx网络HTTP服务器(Linux) (2015-01-23)
- Linux Centos 安装 Nginx HTTP 服务器(一)
- 在Linux服务器上安装nginx(Cent OS+Nginx)
- Linux下安装Nginx服务器
- Linux下安装Nginx服务器
- jeecg 服务器 + linux + nginx 安装
- Linux服务器上安装nginx
- linux系统安装nginx服务器
- Linux下安装Nginx服务器
- Linux下安装Nginx服务器
- Nginx高性能http服务器的安装
- linux上安装http proxy(http代理)服务器
- linux下php源码安装(nginx服务器篇)
- linux-搭建web服务器系列--安装搭建nginx(五)
- linux(centos)下安装nginx服务器
- linux nginx轻量级服务器 - 安装篇
- Linux服务器安装配置nginx 笔记
- 【Linux进阶】CentOS安装Nginx服务器
- poj3694 Network
- 程式上传的功能修改
- 各大云服务器的对比
- get 请求和post请求的区别
- qt5.32静态编译(mingw4.82)
- 安装Nginx网络HTTP服务器(Linux) (2015-01-23)
- C++ 字符串与char*转换
- nginx后端转SSL接收前端请求
- CentOS6.6修改系统盘的默认的LVM卷组VolGroup
- windows2003 iis6.0 配置php5.4.37
- 关于封装2008R2系统的细节说明
- CentOS安装DHCP服务
- 利用ps获取所截取大图里小图的位置坐标方法
- VLAN的Hybrid和Trunk端口有何区别