Nginx 常见错误
1
80 端口被 httpd(apache)占用,修改 httpd(apache) 的端口
vim /etc/httpd/conf/httpd.conf # 修改监ip端口为 127.0.0.1:80
Listen 127.0.0.1:80
/etc/init.d/httpd restart
httpd(apache) 无法访问,使用 nginx 做反向代理
[root@3021094201c5 conf]# cd /usr/local/nginx/conf/
[root@3021094201c5 conf]# grep -v "#" nginx.conf | grep -v "^$"
[root@3021094201c5 conf]# cp nginx.conf nginx.conf.bak
将结果 grep -v "#" nginx.conf | grep -v "^$" 替换到 nginx.conf
修改 nginx.conf 内容为
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include domains/*;
}
[root@3021094201c5 conf]# mkdir domains
[root@3021094201c5 conf]# pwd
/usr/local/nginx/conf/
[root@3021094201c5 conf]# cd domains/
[root@3021094201c5 domains]# touch www.xxx.net # 主机名
[root@3021094201c5 domains]# ll
total 0
-rw-r--r--. 1 root root 0 Jan 24 18:35 www.xxx.net
[root@3021094201c5 domains]# vim www.jfedu.net # nginx 动静分离配置
upstream linux_web {
server 127.0.0.1:80 weight=100 max_fails=2 fail_timeout=30;
}
server {
listen 172.17.0.2:80;
server_name www.jfedu.net localhost;
location / {
proxy_pass http://linux_web;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /var/www/html;
expires 3d;
}
#access_log /data/logs/linux_web/access.log main;
#error_log /data/logs/linux_web/error.log crit;
}
[root@3021094201c5 domains]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@3021094201c5 domains]# /usr/local/nginx/sbin/nginx
[root@3021094201c5 domains]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 49/sshd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN -
tcp 0 0 172.17.0.2:80 0.0.0.0:* LISTEN 3477/nginx
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 3382/httpd
tcp 0 0 :::22 :::* LISTEN 49/sshd