CentOS7安装Nginx

CentOS7安装Nginx - boonya - 博客园

 wget http://nginx.org/download/nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module

报错:

ure: error: the HTTP rewrite module requires the PCRE library.

yum -y install pcre-devel
yum -y install openssl openssl-devel
make
make install

安装汇总:

nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx modules path: "/opt/nginx/modules"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

启动:

/opt/nginx/sbin/nginx

停止
/opt/nginx/sbin/nginx -s stop
重启
/opt/nginx/sbin/nginx -s reload

启动完之后,检验

直接输入公网ip

出现代表成功启动
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

配置文件修改:

 cd /opt/nginx/conf/
 vim nginx.conf

场景一:如果提供下载功能,静态文件或文件的下载

 这里修改为对应的目录即可。根目录 就会指向这个目录。

场景二:443端口”的全部转发到后端8085

       location / {
             proxy_set_header Host  $host;
             proxy_pass http://webs;
             proxy_set_header X-Real-IP  $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
             proxy_http_version 1.1;
             proxy_set_header Connection "";
             proxy_buffer_size       512k;
             proxy_buffers           16 512k;
             proxy_busy_buffers_size 512k;
             expires -1;


       }

其他:

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

加一个安装参数

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

问题一:配置正常,证书也验证了。SSL模块也装了。死活启动就只有80端口,没有443端口。怎么改配置,用nginx -s reload都没有用。解决方案:nginx -s stop ;nginx  。问题解决,我就奇怪了。做下记录。

停止 重启就好了

 /usr/local/nginx/sbin/nginx -s stop

三、配置HTTPS证书并生效

登录服务器如下验证

curl 127.0.0.1:8080/v1/test 可以访问。

 curl -k https://127.0.0.1:443/v1/test 也可以访问。代表负载均衡

proxy_pass http://apps; 将所有请求代理到名为 apps 的 upstream,即 127.0.0.1:8080。 生效了。-k代表暂时跳过SSL证书

[root@ecs-153747 ~]# curl 127.0.0.1:8080/v1/test
init successful[root@ecs-153747 ~]# curl 127.0.0.1:443/v1/test
<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx/1.20.1</center>
</body>
</html>
[root@ecs-153747 ~]# curl -k https://127.0.0.1:443/v1/test
init successful[root@ecs-153747 ~]# 

上面是本机通过校验。

然后apifox分别请求一下8080端口和https的链接(默认443端口)

如果https的链接(默认443端口)不通,还要开通一下阿里云或者华为云的443端口访问权限。

最后成功通过验证。

参考文章:https://www.cnblogs.com/-wei/p/15219624.html

https://www.cnblogs.com/boonya/p/7907999.html

Nginx中安装免费SSL证书开启Https请求_nginx certbot 验证 .well-known 错误-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在CentOS7安装NGINX,你需要按照以下步骤进行操作: 1. 首先,你需要准备好安装NGINX的环境。这包括安装GCC编译器。使用以下命令安装GCC环境: ``` $ yum install -y gcc ``` 2. 下载NGINX安装文件。你可以从NGINX官方网站下载最新版本的NGINX压缩包。将下载好的文件解压缩: ``` $ tar -zxvf nginx-1.20.2.tar.gz ``` 3. 进入解压后的NGINX目录,执行以下命令编译和安装NGINX: ``` $ cd nginx-1.20.2 $ ./configure $ make $ make install ``` 4. 安装完成后,你可以通过以下命令启动NGINX服务: ``` $ nginx ``` 5. 在浏览器访问服务器的IP地址或域名,你应该能够看到NGINX的欢迎页面,这表明NGINX已成功安装并正在运行。如果你想在系统启动时自动启动NGINX服务,可以执行以下命令: ``` $ systemctl enable nginx ``` 请注意,这里提供的步骤是一种常见的安装NGINX的方法,具体的步骤可能因个人系统环境而有所不同。如果你遇到任何问题,可以参考NGINX的官方文档或在相关技术社区寻求帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux操作系统CentOS7安装Nginx[详细版]](https://blog.csdn.net/Wei_Naijia/article/details/124228897)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Centos7安装配置nginx](https://blog.csdn.net/Siebert_Angers/article/details/126960866)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [centos7安装nginx1.16.1](https://download.csdn.net/download/readyoften/13093228)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值