Debian9 从零编译配置Nginx

 

一、准备工作

1.1 更新系统安装包列表

# apt update

1.2 必须软件包

下面都是编译nginx必须的,提前安装好。

# apt install gcc make
# apt install libpcre3 libpcre3-dev //【正则表达式库】 官网http://www.pcre.org/
# apt install openssl libssl-dev //【openssl库】 官网https://www.openssl.org/
# apt install zlib1g-dev

1.3 创建需要使用的目录

创建目录source和web,分别用来放源码和编译后的文件。

# mkdir /source/
# mkdir /web/

二、安装nginx

2.1 安装nginx

[官方网站] http://nginx.org/

命令流程:

# cd /source/
# wget http://nginx.org/download/nginx-1.13.5.tar.gz
# tar -zxf nginx-1.13.5.tar.gz
# cd nginx-1.13.5
# ./configure –prefix=/web/nginx –with-http_ssl_module
# make && make install
–with-http_ssl_module //打开https

三、配置nginx

3.1 打开nginx.conf

vim nginx.conf

3.2 支持php。在server里加入

复制代码
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
复制代码

3.3 支持asp.net。在server里加入

复制代码
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
复制代码

3.4 防火墙添加80、443端口(可选,需要外网访问的)

# firewall-cmd –zone=public –add-port=80/tcp –permanent //–permanent永久生效,没有此参数重启后失效
# firewall-cmd –reload //重新载入

附、常用命令

nginx常用命令

# ln -s /web/nginx/sbin/nginx /usr/local/bin //快捷方式
# /web/nginx/sbin/nginx //启动nginx
# /web/nginx/sbin/nginx -s reload //重启nginx
# /web/nginx/sbin/nginx -s stop //关闭nginx

以下文章点击率最高

Loading…

     

如果这文章对你有帮助,请扫左上角微信支付-支付宝,给于打赏,以助博客运营