NGINX

安装

yum install -y gcc gcc-c++ && cd /usr/local/ && wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz && tar -zxvf pcre-8.33.tar.gz && cd pcre-8.33 && ./configure && make && make install && cd /usr/local/ && wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1j.tar.gz && tar -zxvf openssl-1.0.1j.tar.gz && cd openssl-1.0.1j && ./config && make && make install && cd /usr/local/ && wget http://zlib.net/zlib-1.2.11.tar.gz && tar -zxvf zlib-1.2.11.tar.gz && ./configure && make && make install && cd /usr/local/ && wget http://nginx.org/download/nginx-1.8.0.tar.gz && tar -zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0  && ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.33 --with-zlib=/usr/local/zlib-1.2.11 && make && make install

配置域名和端口

在域名网站,将某域名解析到指定的的服务器IP

这一步在域名管理端完成

建立配置文件夹

在 /usr/local/nginx/conf 文件夹下建立 conf.d文件夹,如下图所示
在这里插入图片描述

编辑nginx.conf

nginx.conf的路径一般为/usr/local/nginx/conf
在nginx.conf文件中添加include conf.d/*.conf;意思是监听conf.d下的所有conf文件。

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    include       conf.d/*.conf;
    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;

添加一级解析

在conf.d文件夹中新建并编辑mecube1.conf文件

事先已经将*.mecube.tyio.net解析到了47.113.186.9,nginx默认会监听80端口。

如果我们想让域名mecube.tyio.net直接访问到8000端口而不是80,则要在mecube.conf里面配置好如下, 该配置的意思是:

  • 监听80端口
  • 并将请求发送给本地的8000端口
server {
    server_name  mecube.tyio.net;
    listen       80;
    # for websocket, do not ignore any line
    proxy_http_version 1.1;
    proxy_connect_timeout 2;
    proxy_read_timeout 300;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Connection "upgrade";
    proxy_set_header Upgrade $http_upgrade;
    location / {
        proxy_pass http://127.0.0.1:8000;
    }
}

添加二级解析

如要添加 mands.mecube.tyio.net到47.113.186.9:14003,只需要再建立一个mands.conf的文件,内容如下

server {
    server_name  mands.mecube.tyio.net;
    listen       80;
    # for websocket, do not ignore any line
    proxy_http_version 1.1;
    proxy_connect_timeout 2;
    proxy_read_timeout 300;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Connection "upgrade";
    proxy_set_header Upgrade $http_upgrade;

    location / {
        proxy_pass http://127.0.0.1:14003;
    }
}
  • 将mands.conf文件放到conf.d文件夹下
    在这里插入图片描述
  • 重启nginx,即可生效
nginx -s reload

常用操作

启动

/usr/local/nginx/sbin/nginx

重启

/usr/local/nginx/sbin/nginx –s reload

停止

/usr/local/nginx/sbin/nginx –s stop

强制关闭

pkill nginx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

行医冶文

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值