nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
连接成功
ubuntu@10-8-60-97:~$ nginx -s reload
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2023/10/16 16:09:10 [warn] 144878#144878: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2023/10/16 16:09:10 [notice] 144878#144878: signal process started
2023/10/16 16:09:10 [error] 144878#144878: open() "/var/run/nginx.pid" failed (2: No such file or directory)
ubuntu@10-8-60-97:~$ sudo vim /etc/nginx/nginx.conf
ubuntu@10-8-60-97:~$ sudo nginx -s reload
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
ubuntu@10-8-60-97:~$ nginx -c /etc/nginx/nginx.conf
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2023/10/16 16:11:02 [warn] 146051#146051: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2023/10/16 16:11:02 [emerg] 146051#146051: open() "/var/log/nginx/access.log" failed (13: Permission denied)
ubuntu@10-8-60-97:~$ sudo nginx -c /etc/nginx/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
ubuntu@10-8-60-97:~$ nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
-bash: syntax error near unexpected token `('
ubuntu@10-8-60-97:~$ sudo nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
-bash: syntax error near unexpected token `('
ubuntu@10-8-60-97:~$ sudo fuser -k 80/tcp
80/tcp: 678 33341 33342 33343 33344
ubuntu@10-8-60-97:~$ sudo nginx -c /etc/nginx/nginx.conf
ubuntu@10-8-60-97:~$ nginx -s reload
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2023/10/16 16:12:41 [warn] 147070#147070: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2023/10/16 16:12:41 [notice] 147070#147070: signal process started
2023/10/16 16:12:41 [alert] 147070#147070: kill(146997, 1) failed (1: Operation not permitted)
ubuntu@10-8-60-97:~$ sudo nginx -s reload
ubuntu@10-8-60-97:~$
关闭单干占用端口
sudo fuser -k 80/tcp
nginx 常用命令
启动
nginx
重启
nginx -s reload
校验
nginx -t
关闭
nginx -s stop
用 这个配置文件 启动nginx
sudo nginx -c /etc/nginx/nginx.conf
防火墙常用 命令
systemctl start firewalld //启动防火墙
systemctl stop firewalld //关闭防火墙
systemctl status firewalld //查看状态
systemctl enable firewalld //开机启动防火墙
systemctl disable firewalld //开机禁用防火墙
firewall-cmd --zone=public --add-port=8080/tcp --permanent //开放某个端口
firewall-cmd --reload //重新加载配置
firewall-cmd --zone=public --list-ports //查看防火墙开放的端口
firewall-cmd --zone=public --query-port=8080/tcp // 查看某个端口的访问权限
firewall-cmd --zone=public --remove-port=8080/tcp --permanent //关闭某个端口的防火墙
同一个服务 配置 两个域名指向
相同端口,不同域名,不同文件 sever_name匹配顺序:
- 精准匹配
- 通配符开头,比如*.example.com
- 通配符结尾,比如www.example.*
- 正则表达式
- 默认值
[root@nginx www]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
keepalive_timeout 65;
#通配符在后的域名
server {
listen 80;
server_name www.haha.*;
location / {
root /www/work_01;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#精确域名
server {
listen 80;
server_name www.haha.com;
location / {
root /www/work_02;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#通配符在前的域名
server {
listen 80;
server_name *.haha.com;
location / {
root /www/work_03;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#正则表达式域名
server {
listen 80;
server_name ~\w+.com;
location / {
root /www/work_04;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@nginx www]# systemctl restart nginx