阿里云服务器是全新的,nginx包是通过ssh工具传上去,这里碰到两个蛋疼的问题。
1.xshell可以直接连,ssh工具不能直接连(如果通过命令scp直接传就不会碰到这个问题)
2.nginx安装好后通过服务器公网ip在浏览器端死活访问不到服务器(cmd窗口是可以ping通的)
问题一个个解决
第一个的解决方案如下:
修改ssh的配置文件 /etc/ssh/sshd_config
在配置文件中添加:
Ciphers aes128-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr,3des-cbc,arcfour128,arcfour256,arcfour,blowfish-cbc,cast128-cbc
MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-sha1-96,hmac-md5-96
重启sshd服务后,即可正常连接。
sudo service ssh restart
另外重启方式还有 sudo /etc/init.d/ssh restart
文件上传上去后安装步骤如下:
1.apt-get update
2.apt-get install libpcre3 libpcre3-dev
3.apt-get install zlib1g-dev
4.apt-get install openssl libssl-dev
5.mkdir -p /var/temp/nginx
6.进入nginx解压后的目录后复制以下全部命令在服务器执行
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_ssl_module
7.在nginx解压后的目录执行make
8.在nginx解压后的目录make install
9. cd /usr/local/nginx/sbin ./nginx -t
显示如下结果:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
10.切换到/user/local/nginx/sbin目录执行命令启动nginx服务器
./nginx
11.浏览器输入http://公网ip或者你的域名访问,成功的话应该出现nginx安装成功的页面,实际上没有,原因就是上面提到的第二个问题
12.常用命令
切换到 /user/local/nginx/sbin
关闭命令:./nginx -s stop
退出命令:./nginx -s quit,等程序执行完毕后关闭,建议使用此命令。
动态加载配置文件./nginx -s reload可以不关闭Nginx的情况下更新配置文件,非常好用!
查看Nginx版本:./nginx -v
第二个问题出现的原因是云服务器初始化的时候的配置:只开了个别的端口,而没有开80的端口(可以通过HTTP协议进行访问的端口)。
解决办法:云服务器的安全组规则添加80端口的访问
做完以上步骤后通过ip或者域名均可出现nginx安装成功页面。