安装nginx yum
直接使用yum安装,但是需要yum的epel库。
如果是通过其他途径安装的nginx,那么配置文件的位置和默认配置是不一样
但配置方法和指令都是都是一模一样。
yum -y install epel-release nginx
```''
使用下面指令可以查看ngingx安装的软件在哪里 (-ql) 。
如果要检索nginx的包名,使用(-qa)
[root@master ~]# rpm -qa |grep nginx
[root@master ~]# rpm -qa |grep nginx
nginx-filesystem-1.20.1-10.el7.noarch
nginx-mod-stream-1.20.1-10.el7.x86_64
nginx-1.20.1-10.el7.x86_64
[root@master ~]# rpm -ql nginx-1.20.1-10.el7.x86_64
如果要查询nginx的配置文件,使用如下命令 -qc
[root@master ~]# rpm -qc nginx-1.20.1-10.el7.x86_64
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
>
/etc/nginx/nginx.conf.default(conf.templ,conf.sample,conf.example)
```nginx
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes 24;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
# 系统能够提供服务的连接数 理论上 是 worker_processes * worker_connections
# 但是受 * hard nofiles number,
# * soft nofiles number
#的影响,可以通过 umlimit -n 使得无上限。或者修改/etc/securiy.limits.conf ,
# 执行 sysctl -p
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# 网站唯一的表示 server_name+port
server {
listen 80;
listen [::]:80;
server_name www.aa.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
}
server {
listen 8081;
listen [::]:8081;
server_name www.aa.com;
root /usr/share/nginx/html/www.aa.com_8081;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
}
server {
listen 80;
listen [::]:80;
server_name www.bb.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
}
启动nginx
[root@master ~]# systemctl start nginx
[root@master ~]# firewall-cmd –add-port=80/tcp –permanent
success
[root@master ~]# firewall-cmd –reload
success
[root@master ~]# curl localhost
以下也可以启动
ngins -s start
nginx -s stop
nginx -s quit
nginx -s reload (重启)
在server section
root: 网站的根地址
假如我的服务器的域名www.yc.com
root /var/www/html/www.yc.com
`
我访问
http://www.yc.com/1.txt
=> /var/www/html/www.yc.com/1.txt
http://www.yc.com/task
=>/var/www/html/www.yc.com/task
=> index.html 如果没有这个文件 403
=> 如果有就显示
http://www.yc.com/wordpress/index.php?a=5&b=6
=>/var/www/html/www.yc.com/wordpress/index.php
http://www.yc.com/wordpress/getgirlsimage.php?leg=long&breast=huge
=>/var/www/html/www.yc.com/wordpress/getgirlsimage.php
`
location / {
root /var/girsls;
}
location ~ (jpeg|mp4)$
{
if ($remote_ip ~= ‘^192’)
return 404;
}
虚拟主机
虚拟主机的配置文件应该写在 /etc/nginx/conf.d/域名.conf
最后编辑:严锋 更新时间:2025-05-09 15:48