记一次阿里云Ubuntu 16.04系统下安装Nginx踩坑经历

阿里云服务器是全新的,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

KexAlgorithms diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group1-sha1,curve25519-sha256@libssh.org

重启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安装成功页面。

转载于:https://juejin.im/post/5a2cd2546fb9a0452405c37a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值