wget https://nginx.org/download/nginx-1.5.9.tar.gz
tar -zxvf nginx-1.5.9.tar.gz
# 不建议
./configure
注意该命令是对nginx进行配置的命令 后面可以带响应的安装目录配置还可以带ssl的配置,后续可以用到,博主一开始没注意导致两次不必要的配置;
# 建议
./configure --prefix=/usr/local/nginx --with-http_stub_status_modul
执行到这一步博主还遇到一个问题就是报错如下:
错误为:./configure: error: the HTTP rewrite module requires the PCRE library
安装pcre-devel解决问题
yum -y install pcre-devel
还有可能出现:
错误提示:
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl= options.
解决办法:
yum -y install openssl openssl-devel
make
make install
记录值对应ecs的ip地址;然后这样子域名就能解析到自己的服务器ip了;
upstream aiyunyou{
server 127.0.0.1:8089;
}
server{
listen 80;
server_name www.***.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://aiyunyou;
proxy_redirect off;
}
配置完成后进行 ./nginx -s reload 重启
此时的配置是将域名监听80端口,然后对本机ip的8089端口进行转发了,配置到这里就可以直接用www.***.com进行访问了,不需要域名+端口号了;
cd /usr/local/nginx/conf
mkdir cert
cd cert
rz
# 以下属性中以ssl开头的属性代表与证书配置有关,其他属性请根据自己的需要进行配置。
server {
listen 443 ssl; #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
server_name localhost; #将localhost修改为您证书绑定的域名,例如:www.example.com。
root html;
index index.html index.htm;
ssl_certificate cert/domain name.pem; #将domain name.pem替换成您证书的文件名。
ssl_certificate_key cert/domain name.key; #将domain name.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;
location / {
root html; #站点目录。
index index.html index.htm;
}
}
重启nginx配置 ./nginx -s reload
配置到这里博主用https访问是失败了,后来发现是ecs忘记开放443端口了,ecs配置一条443端口的开放规则;
upstream aiyunyou{
server 127.0.0.1:8089;
}
server {
listen 80;
server_name www.****.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
server_name www.***.com;
ssl_certificate ./cert/***.pem;
ssl_certificate_key ./cert/**.key;
ssl_session_cache shared:SSL:1m;
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;
location / {
root html;
index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://aiyunyou;
proxy_redirect off;
}
}