一文解决Linux安装Nginx以及常用的配置

服务器:CentOS 8.0 64bit

1.安装编译⼯具
[root@VM-16-6-centos local]# yum install -y gcc gcc-c++
2.安装PCRE
# 1.下载
[root@VM-16-6-centos local]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
# 2.解压
[root@VM-16-6-centos local]# tar -zxvf pcre-8.35.tar.gz
# 3.进⼊pcre⽬录
[root@VM-16-6-centos local]# cd pcre-8.35
# 4.配置
[root@VM-16-6-centos pcre-8.35]# ./configure
# 5.编译安装
[root@VM-16-6-centos pcre-8.35]# make && make install
3.安装SSL库
[root@VM-16-6-centos local]# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
[root@VM-16-6-centos local]# tar -zxvf openssl-1.0.1j.tar.gz
[root@VM-16-6-centos local]# cd openssl-1.0.1j
[root@VM-16-6-centos openssl-1.0.1j]# ./config
[root@VM-16-6-centos openssl-1.0.1j]# make && make install
4.安装zlib库
[root@VM-16-6-centos local]# wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz
[root@VM-16-6-centos local]# tar -zxvf zlib-1.2.11.tar.gz
[root@VM-16-6-centos local]# cd zlib-1.2.11
[root@VM-16-6-centos zlib-1.2.11]# ./configure
[root@VM-16-6-centos zlib-1.2.11]# make && make install
5.安装Nginx
[root@VM-16-6-centos local]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@VM-16-6-centos local]# tar -zxvf nginx-1.16.1.tar.gz
[root@VM-16-6-centos local]# mkdir -p server/nginx
[root@VM-16-6-centos local]# cd nginx-1.16.1
[root@VM-16-6-centos nginx-1.16.1]# ./configure --prefix=/usr/local/server/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
[root@VM-16-6-centos nginx-1.16.1]# make && make install

# 如果在配置过程中出现了以下错误:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
# 执⾏:yum -y install openssl openssl-devel
6.配置Nginx
[root@VM-16-6-centos local]# vim /usr/local/server/nginx/conf/nginx.conf
7.启动/关闭Nginx
[root@VM-16-6-centos local]# cd /usr/local/server/nginx/sbin
# 启动
[root@VM-16-6-centos sbin]# ./nginx
# 关闭
[root@VM-16-6-centos sbin]# ./nginx -s stop
8.配置开机自启

8.1 先创建开机自启脚本

cd /etc/systemd/system
vi nginx.service

# 内容:
[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

8.2 设置开机自启动

systemctl enable nginx

8.3 启动nginx服务

systemctl start nginx.service

8.4 重新启动服务

systemctl restart nginx.service

8.5 查看服务当前状态

systemctl status nginx.service

8.6 停止开机自启动

systemctl disable nginx.service
扩展:
9.Nginx 服务器 SSL 证书安装部署

9.1 下载服务商提供的SSL证书

9.2 上传至Nginx服务器的conf目录下

9.3 编辑 Nginx 根目录下的 conf/nginx.conf 文件

# 修改内容
server {
        #SSL 访问端口号为 443
        listen 443 ssl; 
        #填写绑定证书的域名
        server_name chenxp.top; 
        #证书文件名称
        ssl_certificate chenxp.top_bundle.crt; 
        #私钥文件名称
        ssl_certificate_key chenxp.top.key; 
        ssl_session_timeout 5m;
        #请按照以下协议配置
        ssl_protocols TLSv1.2 TLSv1.3; 
        #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; 
        ssl_prefer_server_ciphers on;
        location / {
           #网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
           #例如,您的网站运行目录在/etc/www下,则填写/etc/www。
            root html; 
            index  index.html index.htm;
        }
    }

9.4 在 Nginx 根目录下,通过执行以下命令验证配置文件问题。

[root@VM-16-6-centos sbin]# ./nginx -t

9.5 重启Nginx,即可使用 https访问

[root@VM-16-6-centos sbin]# ./nginx -s reload
10.配置gzip压缩

10.1 编辑 Nginx 根目录下的 conf/nginx.conf 文件

[root@VM-16-6-centos ~]# cd /usr/local/server/nginx/conf
[root@VM-16-6-centos conf]# vim nginx.conf

#在http{}下添加以下内容
#是否启动gzip压缩,on代表启动,off代表开启
gzip  on; 
#需要压缩的常见静态资源
gzip_types text/plain application/javascript   application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
#由于nginx的压缩发生在浏览器端而微软的ie6很坑爹,会导致压缩后图片看不见所以该选项是禁止ie6发生压缩
gzip_disable "MSIE [1-6]\.";
#如果文件大于1k就启动压缩
gzip_min_length 1k;
#以16k为单位,按照原始数据的大小以4倍的方式申请内存空间,一般此项不要修改
gzip_buffers 4 16k;
#压缩的等级,数字选择范围是1-9,数字越小压缩的速度越快,占用cpu也越大
gzip_comp_level 3;

10.2 重启Nginx服务

[root@VM-16-6-centos conf]# cd /usr/local/server/nginx/sbin
[root@VM-16-6-centos sbin]# ./nginx -t
[root@VM-16-6-centos sbin]# ./nginx -s reload

10.3 检验是否开启成功

通过控制台查看打开响应头中的Content-Encoding选项,如果出现gzip,则开启成功。

image-20220524123921195

### IntelliJ IDEA 中通义 AI 功能介绍 IntelliJ IDEA 提供了一系列强大的工具来增强开发体验,其中包括与通义 AI 相关的功能。这些功能可以帮助开发者更高效地编写代并提高生产力。 #### 安装通义插件 为了使用通义的相关特性,在 IntelliJ IDEA 中需要先安装对应的插件: 1. 打开 **Settings/Preferences** 对话框 (Ctrl+Alt+S 或 Cmd+, on macOS)。 2. 导航到 `Plugins` 页面[^1]。 3. 在 Marketplace 中搜索 "通义" 并点击安装按钮。 4. 完成安装后重启 IDE 使更改生效。 #### 配置通义服务 成功安装插件之后,还需要配置通义的服务连接信息以便正常使用其提供的各项能力: - 进入设置中的 `Tools | Qwen Coding Assistant` 菜单项[^2]。 - 填写 API Key 和其他必要的认证参数。 - 测试连接以确认配置无误。 #### 使用通义辅助编程 一旦完成上述准备工作,就可以利用通义来进行智能编支持了。具体操作如下所示: ##### 自动补全代片段 当输入部分语句时,IDE 将自动提示可能的后续逻辑,并允许一键插入完整的实现方案[^3]。 ```java // 输入 while 循环条件前半部分... while (!list.isEmpty()) { // 激活建议列表选择合适的循环体内容 } ``` ##### 解释现有代含义 选中某段复杂的表达式或函数调用,右键菜单里会有选项可以请求通义解析这段代的作用以及优化意见。 ##### 生产测试案例 对于已有的业务逻辑模块,借助于通义能够快速生成单元测试框架及初始断言集,减少手动构建的成本。 ```python def test_addition(): result = add(2, 3) assert result == 5, f"Expected 5 but got {result}" ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值