- 建普通用户
[root@VM_0_3_centos /]# useradd -d /nginx -m nginx
[root@VM_0_3_centos /]# chmod 777 /nginx
[root@VM_0_3_centos /]# yum install lrzsz
- postgres用户下载代码并解压缩
su - nginx
[nginx@VM-16-6-centos ~]$ wget https://nginx.org/download/nginx-1.18.0.tar.gz
[nginx@VM-16-6-centos ~]$ tar -xzvf nginx-1.18.0.tar.gz
新服务器,直接安装报错
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
先root安装依赖,不能root安装依赖自己下载安装包安装openssl-fips-2.0.2.tar.gz
zlib-1.2.7.tar.gz
pcre-8.21.tar.gz
nginx-1.18.0.tar.gz
[root@VM-16-6-centos ~]# yum -y install gcc gcc-c++ autoconf automake make
[root@VM-16-6-centos ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
加入是自己安装的其他依赖,"–with-xxx="的值是解压对应依赖的目录,不是安装目录
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/install/nginx --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 --with-openssl=../openssl-fips-2.0.2
安装:
[nginx@VM-16-6-centos nginx-1.18.0]$ ./configure --prefix=/nginx/nginx
make
make install
- 修改配置文件,启动
cd /nginx/nginx/conf
[nginx@VM-16-6-centos conf]$ cp nginx.conf nginx.conf.20220402
vim nginx.conf
#改server下的listen端口号,这里直接把访问8000的端口都转到自己服务器9000端口,
server {
listen 8000;
server_name localhost;
location / {
root html;
index index.html index.htm;
#add_header 'Access-Control-Allow-Origin' "www.jjjj.com";
proxy_pass http://127.0.0.1:9000;
client_max_body_size 100M;
}
[nginx@VM-16-6-centos conf]$ cd ../sbin/
[nginx@VM-16-6-centos sbin]$ ./nginx
[nginx@VM-16-6-centos sbin]$
linux操作命令
启动服务:nginx 退出服务:nginx -s quit 强制关闭服务:nginx -s stop 重载服务:nginx -s reload (重载服务配置文件,类似于重启,但服务不会中止) 验证配置文件:nginx -t 使用配置文件:nginx -c "配置文件路径" 使用帮助:nginx -h
配置环境变量,不用每次到sbin下执行命令
cd ~
vim ./bash_profile
NGHOME=/nginx/nginx/sbin
PATH=$NGHOME:$HOME/bin
export PATH