Nginx 环境搭建

由于242 服务器崩掉,需要在193上重新搭建Nginx环境,以下为安装步骤
下载源码安装包 在192.168.10.193服务器上,我将安装包放在了/tmp/softwares/目录下,所有的安装包都放在这里,我们采用源码安装方式

tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
进入目录后要进行编译配置

下面是242 的配置 路径

./configure --user=www --group=www --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --sbin-path=/usr/sbin/nginx --error-log-path=/data/logs/nginx/nginx_error.log --http-log-path=/data/logs/nginx/nginx_access.log --pid-path=/usr/local/nginx/run/nginx.pid --lock-path=/usr/local/nginx/lock/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --http-client-body-temp-path=/usr/local/nginx/client_body_temp/ --http-proxy-temp-path=/usr/local/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/nginx/fcgi_temp --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/scgi_temp
下面是193的配置路径,不过后来又重新编译,按照242的路径

./configure --user=www --group=www --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --sbin-path=/usr/sbin/nginx --error-log-path=/data/logs/nginx/nginx_error.log --http-log-path=/data/logs/nginx/nginx_access.log --pid-path=/usr/local/nginx/run/nginx.pid --lock-path=/usr/local/nginx/lock/nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/tmp/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/tmp/nginx/fcgi --http-uwsgi-temp-path=/usr/local/nginx/tmp/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/tmp/nginx/scgi

以上命令是将nginx安装到了 /usr/local/nginx 目录下

make && make install
安装完成后 进入到/usr/local/nginx 目录下

cd /usr/local/nginx
在这里创建一个目录 vhost 用来放 所有nginx 项目的server配置

mkdir vhost
vim nginx.conf
在结尾 } 前 加上下面一行

include vhost/*.conf
保存退出

由于配置的时候用户为www,我们需要添加www这个用户

useradd -r www -s /bin/false -M
安装完毕,测试一下

nginx -v
nginx -t
nginx -s reload
如果nginx -t 的时候 显示没有配置文件

nginx -c /usr/local/nginx/nginx.conf
然后重新
nginx -t
nginx -s reload

成功没有捷径
原文地址:https://www.cnblogs.com/orpheus89/p/9838660.html