記一次阿里雲Ubuntu 16.04系統下安裝Nginx踩坑經歷

herevra發表於2017-12-12

阿里雲伺服器是全新的,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埠的訪問

記一次阿里雲Ubuntu 16.04系統下安裝Nginx踩坑經歷

做完以上步驟後通過ip或者域名均可出現nginx安裝成功頁面。

相關文章