1、软件在外链网址已屏蔽下载
2、安装方法及参数说明在外链网址已屏蔽,文档说明外链网址已屏蔽(有关nginx的详细说明都在这里了)
3、开始安装,这里我们选择的默认的安装(未加任何的选项)。
[jhj@localhost nginx-1.6.0]$ ./configure
执行上述命令后,会在最后给出一些默认的配置信息,包括安装位置等一些信息,如下:
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
好了,试着make && make install一下吧
[root@localhost nginx-1.6.0]# make && make install
安装好了,我们试着启动一下吧
[root@localhost 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)
nginx: [emerg] still could not bind()
怎么回事?这么多failed。这里应该是80端口被占用了,因为机子里面有apache在运行着。好吧,我们换一个
试着改一下配置文件
[root@localhost nginx]# vi ./conf/nginx.conf
server {
listen 8000; #改为8000总可以了吧
server_name localhost;
#这里已经省略了一些内容
}
重新启动了下,可以了。
[root@localhost nginx]# ps aux | grep nginx
root 4622 0.0 0.0 5292 552 ? Ss 05:15 0:00 nginx: master process ./sbin/nginx
nobody 4623 0.0 0.0 5476 908 ? S 05:15 0:00 nginx: worker process
root 4649 0.0 0.0 4356 720 pts/0 S+ 05:19 0:00 grep nginx
在浏览器访问下外链网址已屏蔽,说明成功了(文件在nginx安装文件夹内的html/index.html)
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer tonginx.org.
Commercial support is available at.
Thank you for using nginx.
4、好了静态html文件算是可以解析了,可是php的文件还没有可以解析,那么配置吧。
网上查了下资料发现要支持php要使用fastcgi模式,而之前在虚拟机安装php的时候没有安装支持fastcgi,这个东西貌似不重新编译又不行(行吗?)。
重新安装php(增加参数--enable-fpm)并支持fastcgi后,重新配置下nginx与php
(
题外:重新编译--enable-fpm的时候出现了/usr/bin/ld: cannot find -lltdl,解决方法如下(来源:外链网址已屏蔽):
查看/usr/lib库中是否存在,我这里发现是存在的
[root@localhost lib]# ll | grep libltdl
lrwxrwxrwx. 1 root root 16 May 2 2013 libltdl.so.7 -> libltdl.so.7.2.1
-rwxr-xr-x. 1 root root 36852 Aug 25 2010 libltdl.so.7.2.1
#关键在下边,这样设置后就可以过make了
[root@localhost lib]# ln -svf libltdl.so.7.2.1 libltdl.so
[root@localhost lib]# ll | grep libltdl
lrwxrwxrwx. 1 root root 16 May 27 06:50 libltdl.so -> libltdl.so.7.2.1
lrwxrwxrwx. 1 root root 16 May 2 2013 libltdl.so.7 -> libltdl.so.7.2.1
-rwxr-xr-x. 1 root root 36852 Aug 25 2010 libltdl.so.7.2.1
)
以默认配置启动php-fpm
[root@localhost sbin]# ./php-fpm
设置nginx
server {
#这里已经省略了一些内容
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
重启nginx
[root@localhost conf]# ../sbin/nginx -s reload
html目录
[root@localhost html]# pwd;ll;cat t.php
/usr/local/nginx/html
total 12
-rw-r--r--. 1 root root 537 May 27 05:05 50x.html
-rw-r--r--. 1 root root 612 May 27 05:05 index.html
-rw-r--r--. 1 root root 16 May 27 05:23 t.php
echo 111;
打开浏览器外链网址已屏蔽
输出了111,成功了。