windows
nginx下载地址:
链接:https://pan.baidu.com/s/13XXWmlcCCGw-eNu3NRFixg
提取码:i5df
直接将nginx解压即可使用(可以解压到任何路径下)。
具体的启动操作可以参考http://www.wuwenhui.cn/4570.html
linux
准备:linux虚拟机,SecureCRT
nginx下载地址:
链接:https://pan.baidu.com/s/1fZcVRhI1PUR6tkgdmrF9Vw
提取码:gayc
1、用SecureCRT连接虚拟机
1.1 查找虚拟机的ip地址
- 在虚拟机的桌面空白处右击,选择在终端中打开
- 输入ifconfig,回车,找到虚拟机的ip地址
1.2 打开SecureCRT,创建连接
- 输入ip地址和用户名
- 输入密码
- 连接成功
2、安装niginx
- 输入
ps -ef | grep nginx
,未安装nginxze则显示以下结果:
[root@Linux ~]# ps -ef | grep nginx
root 3086 3044 0 15:45 pts/1 00:00:00 grep nginx
- 创建新用户并设置密码(注意,输入密码的过程中是看不见密码的,回车后会显示无效的密码,不必理会,重新输入新的密码确认即可):
[root@Linux ~]# useradd nginx
[root@Linux ~]# passwd nginx
更改用户 nginx 的密码 。
新的 密码:
无效的密码: 过短
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
- 这个时候,linux虚拟机的home目录下会自动生成nginx目录,然后我们上传nginx-1.10.0.tar.gz文件到目录:
/home/nginx/
。
Alt+P打开SFTP窗口,转到/home/nginx/
目录,然后将nginx-1.10.0.tar.gz文件直接拖拽到SFTP窗口,即可完成上传(nginx-1.10.0.tar.gz所在路径最好没有中文)。
- 我们回到初始界面,到
/home/nginx/
目录下输入ll
查看文件是否已成功上传
[root@Linux ~]# cd /home/nginx/
[root@Linux nginx]# ll
总用量 888
-rw-r--r--. 1 root root 908954 4月 6 20:15 nginx-1.10.0.tar.gz
- 将nginx-1.10.0.tar.gz解压
[root@Linux nginx]# tar -xvf nginx-1.10.0.tar.gz
- 配置
[root@Linux nginx]# cd nginx-1.10.0
[root@Linux nginx-1.10.0]# ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
checking for OS
+ Linux 2.6.32-573.el6.i686 i686
checking for C compiler ... not found
./configure: error: C compiler cc is not found
- 执行命令后,会显示缺少C编译器(我这台虚拟机是新建的)。既然没有,那就下载
yum install gcc
。但是又报错了。
[root@Linux nginx-1.10.0]# yum install gcc
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/i386/6/base/mirrorlist.txt
错误:Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
- 因为我的虚拟机版本是centos6,而centos6的默认源在2012年-12月左右被官方搞掉了。
修复:
[root@Linux nginx-1.10.0]# sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
[root@Linux nginx-1.10.0]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@Linux nginx-1.10.0]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
102 1749 102 1749 0 0 2126 0 --:--:-- --:--:-- --:--:-- 10600
这个时候再执行yum install gcc
命令,就不会报错了。在下载过程中,会出现确定吗?[y/N]:
的提问,我们直接输入y+Enter即可。
事实上,我们还需要:pcre-deve和zlib-devel库,执行:
yum -y install pcre-devel
yum install -y zlib-devel
再次执行:./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
。
当运行到最后,出现以下内容时,就证明配置成功了。
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
nginx path prefix: "/opt/nginx"
nginx binary file: "/usr/bin/nginx"
nginx modules path: "/opt/nginx/modules"
nginx configuration prefix: "/opt/nginx/conf"
nginx configuration file: "/opt/nginx/conf/nginx.conf"
nginx pid file: "/opt/nginx/logs/nginx.pid"
nginx error log file: "/opt/nginx/logs/error.log"
nginx http access log file: "/opt/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"
- 编译安装
[root@Linux nginx-1.10.0]# make && make install
- 启动nginx
直接输入命令nginx
即可启动。然后用ps -ef | grep nginx
查看进程,如果进程没有三个,则可能是端口被占用了。可以用fuser -k 80/tcp
关闭端口为80的进程再重新启动nginx。要注意不能多次启动nginx,否则会显示端口已被占用。
[root@Linux nginx-1.10.0]# nginx
[root@Linux nginx-1.10.0]# ps -ef | grep nginx
root 623 1 0 19:05 ? 00:00:00 nginx: master process nginx
nobody 624 623 0 19:05 ? 00:00:00 nginx: worker process
root 626 4278 0 19:05 pts/3 00:00:00 grep nginx
-
关闭防火墙
永久关闭:chkconfig iptables off
暂时关闭:service iptables stop -
访问nginx
如果安装成功了,在主机的浏览器中输入虚拟机的IP地址,我们就可以看到nginx的欢迎页面了。若看不到这个界面,可以尝试重启虚拟机,并启动nginx,再重新访问。