最近無意間發現Nginx官方提供了Yum源。因此寫個文章記錄下。
1、添加源
默認情況Centos7中無Nginx的源,最近發現Nginx官網提供了Centos的源地址。因此可以如下執行命令添加源:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安裝Nginx
通過yum search nginx看看是否已經添加源成功。如果成功則執行下列命令安裝Nginx。
sudo yum install -y nginx
查看安裝位置
find /|grep nginx.conf
3、啓動Nginx並設置開機自動運行
sudo systemctl start nginx.service sudo systemctl enable nginx.service
4、瀏覽查看效果
在瀏覽器中輸入您的服務器地址:http://www.dearcloud.cn/
nginx同時使用(http)80和(https)443端口
server {
listen 443 ssl; #監聽https 443時需加ssl
server_name ; #你的域名
ssl on;
ssl_certificate ; #證書路徑
ssl_certificate_key ; #證書路徑
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8080; #代理地址
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
server_name ; #你的域名
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8081; #代理地址
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}