阿里云CentOS7安装nginx
阿里云CentOS7安装nginx1、安装gcc插件我使用的连接工具MobaXterm。连接上后先看自己是不是有gcc插件查看gcc版本gcc -v阿里云CentOS一般安装的有。没有的这个就使用yum命令安装:yum -y install gcc2、pcre、pcre-devel安装pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所
阿里云CentOS7安装nginx
1、安装gcc插件
我使用的连接工具MobaXterm。连接上后先看自己是不是有gcc插件
查看gcc版本
gcc -v
阿里云CentOS一般安装的有。
没有的这个就使用yum命令安装:
yum -y install gcc
2、pcre、pcre-devel安装
pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。
安装命令
yum install -y pcre pcre-devel
3、zlib安装
安装命令
yum install -y zlib zlib-devel
4、安装openssl
openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔。。。。。。
安装命令
yum install -y openssl openssl-devel
准备工作完成然后开始安装nginx
创建一个文件夹我是将文件创建 usr/local/里面
mkdir /usr/local/nginx/
创建后切换到这个目录
cd /usr/local/nginx/
开始下载文件
wget http://nginx.org/download/nginx-1.9.9.tar.gz
解压文件
tar -zxvf nginx-1.9.9.tar.gz
会多一个文件夹 nginx-1.9.9切换进去
cd /usr/local/nginx/nginx-1.9.9
执行这三个命令
./configure
make
make install
执行完成后返回上一级 也就是/usr/local/nginx/
cd ../
你会发现多了几个文件,其中sbin中的文件可以用来启动nginx。conf文件夹里面的有nginx.conf就是配置文件。在里面配置监听端口等。文章末尾有具体配置。
切换到sbin文件里面
cd sbin
切换后使用命令启动
./nginx
查看进程:
ps -ef |grep nginx
这里显示27793是我的主进程。
杀死进程关闭:kill -9 27793
修改文件后先杀死进程然后回到sbin文件再次启动。为什么要这样做因为使用yum安装就会这样…除非修改配置文件请参考.这篇文章:
最后访问你服务器ip一般安装后默认监听的是80端口。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
#监听的端口
listen 80;
#域名-可以是ip地址,可以是网址.具体你看你的服务器解析的有没有域名
server_name 0.0.0.0;
#charset koi8-r;
#access_log logs/host.access.log main;
#这是就是对应的网址:比如监听到ip:80/user访问他就会跳到对应的本地的ip:8099/user
#如果对应多个端口转发就继续往下看比如mysql:3306、rabbitmq:15672
location /user{
#root html;
#index index.html index.htm;
#proxy_set_header Host $host;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8099/user;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#监听8080端口跳转本地15672端口
#开端口你要去阿里云的控制台开启端口,当然你也可以都用80端口监听
#在location /后面任意添加就ok
server {
#监听的端口当有人访问服务器-ip:8080端口就会跳转-ip:15672
listen 8080;
server_name 0.0.0.0;
location / {
#root html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:15672;
}
}
#代理3306端口就把上面一个server复制粘贴一个
# another virtual host using mix of IP-, name-, and port-based configuration
#
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
搞定!
更多推荐
所有评论(0)