centos7下安装nginx
https://www.jianshu.com/p/97cdbeebef96
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
二、安装 PCRE(让 Nginx 支持 Rewrite 功能)
#下载最新版本的,注意不要用pcre2
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
tar -xvf pcre-8.42.tar.gz
cd pcre-8.42
#安装编译
./configure
make && make install
#查看pcre版本
pcre-config --version
三、安装nginx
#下载
wget https://nginx.org/download/nginx-1.15.9.tar.gz
tar -xvf nginx-1.15.9.tar.gz
cd nginx-1.15.9
#编译安装
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.42
make && make install
#查看版本
/usr/local/webserver/nginx/sbin/nginx -v
三、nginx配置
#创建 Nginx 运行使用的用户 www
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
#设置包含多个配置文件,在nginx.conf底部添加
include vhost/*.conf;
#启动
/usr/local/webserver/nginx/sbin/nginx
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
# /usr/local/webserver/nginx/conf/vhost/demo.tilesrow.com.conf
server
{
listen 80;
#listen [::]:80;
server_name xx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /data/project/demo1;
access_log /usr/local/webserver/nginx/logs/xx.com.log;
}
内网映射端口配置
server
{
listen 80;
#listen [::]:80;
server_name demo.xx.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8001;
}
access_log /usr/local/webserver/nginx/logs/demo.xx.com.log;
}
[Unit]
Description=nginx Service
After=network.target remote-fs.target nss-lookup.target
[Service]
WorkingDirectory=/usr/local/webserver/nginx/sbin/
Type=forking
User=root
Group=root
ExecStart=/usr/local/webserver/nginx/sbin/nginx
ExecReload=/usr/local/webserver/nginx/sbin/nginx -s reload
ExecStop=/usr/local/webserver/nginx/sbin/nginx -s stop
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-nginx
[Install]
WantedBy=multi-user.target
作者:奋斗_登
链接:https://www.jianshu.com/p/97cdbeebef96
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。