腾讯云服务器从购买到使用-第二章-Nginx安装使用

1.安装环境。

本教程使用Centos7作为安装环境。

(1).gcc

安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:

yum install gcc-c++

(2).PCRE

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel

(3).zlib

zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel

(4).openssl

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。

nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel

2.下载nginx。

wget http://nginx.org/download/nginx-1.8.0.tar.gz 

3.编译安装。

tar -zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

./configure --prefix=/usr/local/nginx

make

make  install

安装成功查看安装目录 :安装目录对应参数设置里面

4.启动ginx。

cd /usr/local/nginx/sbin/

./nginx

查看进程,master是主进程,worker是工作进程。

ps -ef | grep nginx

注意:执行./nginx启动nginx,这里可以-c指定加载的nginx配置文件,如下:

./nginx -c /usr/local/nginx/conf/nginx.conf

如果不指定-c,nginx在启动时默认加载conf/nginx.conf文件,此文件的地址也可以在编译安装nginx时指定./configure的参数(--conf-path=指向配置文件(nginx.conf))


5.停止nginx。

方式1,快速停止:

cd /usr/local/nginx/sbin

./nginx -s stop

此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

方式2,完整停止(建议使用):

cd /usr/local/nginx/sbin

./nginx -s quit

此方式停止步骤是待nginx进程处理任务完毕进行停止。

 

6.重启nginx。

方式1,先停止再启动(建议使用):

对nginx进行重启相当于先停止nginx再启动nginx,即先执行停止命令再执行启动命令。

./nginx -s quit

./nginx

方式2,重新加载配置文件:

当nginx的配置文件nginx.conf修改后,要想让配置生效需要重启nginx,使用-s reload不用先停止nginx再启动nginx即可将配置信息在nginx中生效。

./nginx -s reload
 

7.开机自动启动nginx。

(1).vi /etc/init.d/nginx  (输入以下代码)


#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx    #启动路径和自己安装一致
nginx_config=/usr/local/nginx/conf/nginx.conf   #配置文件路径和自己安装路径一致
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

:wq  保存并退出

(2).设置文件的访问权限

chmod a+x /etc/init.d/nginx

(3).开机启动,加入rc.local文件中

vi /etc/rc.local

加入一行  /etc/init.d/nginx start    

:wq保存并退出,下次重启系统会生效。

 

8.Nginx代理设置。

(1).Nginx之Jenkinx代理设置。

server {
    listen       80;
    server_name  jenkins.xxx.com;

    location / {
        proxy_pass http://127.0.0.1:9090;
        proxy_read_timeout  90;
            proxy_set_header X-Forwarded-Host $host:$server_port;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr; 
    }
}

(2).Nginx之nexus代理设置。

server {
    listen       80;
    server_name  maven.xxx.com;

    location / {
        proxy_pass http://maven.xxx.com:9091; 
    }
}

(3).Nginx之html代理设置。

server {
    listen       80;
    server_name  xxx.net www.xxx.net;

    location / {
        root   /home/www/xxx;
        index  index.html index.htm;
    }
}

(4).Nginx之tomcat代理设置。

server {
    listen       80;
    server_name  api.xxx.com;

    location / {
        proxy_pass http://127.0.0.1:8080; 
    }
}

(5).Nginx之默认代理设置。

server {
    listen       80;
    server_name  localhost;

    location / {
        root   html;
        index  index.html index.htm;
    }

    #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:8080;
    #    fastcgi_index  index;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
}

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你的问题是关于腾讯云服务器使用nginx-ingress代理nacos端口,并使用域名访问。那么我可以为你解答。 首先,为了在腾讯云服务器使用nginx-ingress代理nacos端口,并使用域名访问,你需要完成以下步骤: 1. 在腾讯云服务器安装nginx-ingress。你可以使用helm chart来完成安装安装完成后,你可以通过kubectl get svc -n ingress-nginx查看nginx-ingress的service。 2. 在nacos配置中心的deployment中添加annotations,使其能够被nginx-ingress识别。例如: ``` apiVersion: apps/v1 kind: Deployment metadata: name: nacos namespace: default labels: app: nacos spec: replicas: 1 selector: matchLabels: app: nacos template: metadata: labels: app: nacos annotations: nginx.ingress.kubernetes.io/rewrite-target: / nginx.ingress.kubernetes.io/proxy-body-size: "0" spec: containers: - name: nacos image: nacos/nacos-server:latest ports: - containerPort: 8848 ``` 3. 创建ingress资源,并将其与nacos的service关联。例如: ``` apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: nacos-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - host: nacos.example.com # 这里填写你的域名 http: paths: - path: /nacos backend: serviceName: nacos servicePort: 8848 ``` 4. 最后,在腾讯云域名管理中添加一条记录,将域名解析到nginx-ingress的service对应的IP地址。这样你就可以通过域名访问nacos了。 希望这些步骤能够帮助到你。如果你还有其他问题,可以继续问我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值