nginx的安装
提前关闭好防火墙和selinux
下载nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
解压
[root@localhost ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.20.2.tar.gz
nginx-1.20.2 nginx-1.22.0.tar.gz
创建系统用户nginx
[root@localhost ~]# cd nginx-1.20.2/
[root@localhost nginx-1.20.2]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@localhost nginx-1.20.2]#
[root@localhost nginx-1.20.2]# useradd -rMs /sbin/nologin nginx
[root@localhost nginx-1.20.2]#
安装依赖环境
[root@localhost nginx-1.20.2]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make
安装过程略....
创建日志存放目录
[root@localhost nginx-1.20.2]# mkdir -p /var/log/nginx
[root@localhost nginx-1.20.2]# chown -R nginx.nginx /var/log/nginx
[root@localhost nginx-1.20.2]#
编译安装
[root@localhost nginx-1.20.2]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.20.2]# make -j 1
安装过程略....
[root@localhost nginx-1.20.2]# make install
查看并开启服务
[root@localhost nginx]# cd /usr/local/nginx
[root@localhost nginx]# ls sbin/
nginx
[root@localhost nginx]# du -sh sbin/nginx
6.1M sbin/nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx
[root@localhost nginx]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
访问网站
nginx安装后配置
配置环境变量
[root@localhost nginx]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost nginx]# source /etc/profile.d/nginx.sh
[root@localhost nginx]# cd
[root@localhost ~]# which nginx
/usr/local/nginx/sbin/nginx
[root@localhost ~]#
配置开机自启
[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# nginx -s stop
[root@localhost ~]# systemctl status nginx.service
● nginx.service - nginx server daemon
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; >
Active: inactive (dead)
[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# systemctl status nginx.service
[root@localhost ~]# systemctl enable nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# systemctl status nginx.service
● nginx.service - nginx server daemon
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; v>
Active: active (running) since Mon 2022-10-10 22:09:20 CST; 23s a>
Main PID: 57854 (nginx)
Tasks: 2 (limit: 23500)
Memory: 2.2M
CGroup: /system.slice/nginx.service
-c //指定配置文件的路径
[root@localhost ~]# cp /usr/local/nginx/conf/nginx.conf /opt/
[root@localhost ~]# cp /usr/local/nginx/conf/mime.types /opt/
[root@localhost ~]# vim /opt/nginx.conf
server {
listen 8080; //改8080
server_name localhost;
[root@localhost ~]# nginx -c /opt/nginx.conf
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:8080 0.0.0.0:*
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost ~]#
用于调试、定位问题的配置参数
daemon {on|off}; //是否以守