当前位置:   article > 正文

linux nginx搭建与配置_linux配置nginx

linux配置nginx

安装

  • 方法一,使用epel源
    安装epel源

yum -y install epel-release

出现epel源

[root@localhost yum.repos.d]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-Media.repo          epel.repo
CentOS-CR.repo         CentOS-Sources.repo        epel-testing.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
CentOS-fasttrack.repo  CentOS-x86_64-kernel.repo

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

yum -y install nginx

  • 方法二,使用官方提供的nginx源

rpm -uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
修改yum源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx.repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

启动Nginx并设置开机启动

systemctl start nginx.service
systemctl enable nginx.service
检查安装版本
nginx -v
重启
/usr/sbin/nginx -s stop
/usr/sbin/nginx -s reload

配置文件

配置文件位置:

/etc/nginx

[root@localhost yum.repos.d]# ls /etc/nginx
conf.d                  koi-utf             scgi_params
default.d               koi-win             scgi_params.default
fastcgi.conf            mime.types          uwsgi_params
fastcgi.conf.default    mime.types.default  uwsgi_params.default
fastcgi_params          nginx.conf          win-utf
fastcgi_params.default  nginx.conf.default
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 查看nginx.conf主配置文件

  • 查找默认的安装位置

find / -name *nginx*

[root@localhost /]# find / -name *nginx*
/run/nginx.pid
/sys/fs/cgroup/systemd/system.slice/nginx.service
/etc/systemd/system/multi-user.target.wants/nginx.service
/etc/systemd/system/nginx.service.d
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/var/tmp/systemd-private-9fbd51e7c0714a37bc28f8f7aee49468-nginx.service-CmQIIT
/var/lib/yum/yumdb/n/f8a4655b1aa3ca9c0275be2d64ea287e99fc7217-nginx-filesystem-1.20.1-9.el7-noarch
/var/lib/yum/yumdb/n/85502cf4b35f5368569b0b62e550755496b72249-nginx-1.20.1-9.el7-x86_64
/var/lib/nginx
/var/log/nginx
/tmp/systemd-private-9fbd51e7c0714a37bc28f8f7aee49468-nginx.service-szPRoy
/usr/bin/nginx-upgrade
/usr/sbin/nginx
/usr/lib/systemd/system/nginx.service
/usr/lib/systemd/system/nginx.service.d
/usr/lib64/nginx
/usr/share/doc/nginx-1.20.1
/usr/share/licenses/nginx-1.20.1
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx-upgrade.8.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html/nginx-logo.png
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/ftplugin/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 查看启动的service配置
[root@localhost /]# cat /etc/systemd/system/multi-user.target.wants/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

可以发现安装到了/usr/sbin/nginx下

文件配置解读

[root@localhost /]# cat /etc/nginx/nginx.conf

# 运行用户
user nginx;
# 启动进程 一般与cpu数量相等
worker_processes auto;
# 全局错误日志
error_log /var/log/nginx/error.log;
# 进程日志文件位置
pid /run/nginx.pid;

# 包含了子配置文件
include /usr/share/nginx/modules/*.conf;
# 工作模式以及链接上限
events {
   

    use epoll;
    #epoll 是多路复用,IO模型中的一种&#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/103717
推荐阅读
相关标签
  

闽ICP备14008679号