我正在运行一个 LEMP 堆栈,该堆栈曾为来自本地和远程 IP 地址的请求提供服务,但现在它根本不为请求提供服务。当它停止服务远程请求时,我试图在其上设置虚拟主机。我尝试修复此问题,但现在它也不满足本地请求。每当我尝试从 LAN 或 Internet 访问该网站时,我都会收到一条错误消息(在 Chrome 中):“无法访问此网站... ERR_CONNECTION_REFUSED”
我可以 ping 通服务器的内部 IP 地址、外部 IP 地址和域名,但无法加载网站。我还通过 SSH 进行处理,而不是直接在机器上进行。这是一个配置问题,而不是网络问题。
这是我网站的配置文件:/etc/nginx/sites-available/anneliesephotos.com
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/ftp/lauren/anneliesephotos;
index index.php index.html index.htm index.nginx-debian.html;
server_name anneliesephotos.com;
# www.anneliesephotos.com;
#server_name 99.104.137.87;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
location ~ /\.ht {
deny all;
}
}
这是我的 /etc/nginx/sites-available/default 文件的内容:
server {
listen 80;
listen [::]:80;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
当我查看 Nano 中的默认文件时,行“expire max;”、“log_not_found off;”以及它们后面下一行的右花括号左侧有实心红色块,几乎就像一个错误。
/etc/nginx/nginx.conf 文件如下所示:
user www-data;
worker_processes 2;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
#
server_tokens off;
#server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie_6";
gzip_min_length 1100;
gzip_vary on;
gzip_proxied any;
# gzip_comp_level 6;
gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml
application/x-font-ttf font/opentype application/vnd.ms-fontobject;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.*;
}
/etc/nginx/sites-enabled 具有指向 /etc/nginx/sites-available/anneliesephotos 文件夹的符号链接
lrwxrwxrwx 1 root root 42 Nov 24 02:44 anneliesephotos -> /etc/nginx/sites-available/anneliesephotos
当我运行时netstat -tlpn
,我发现由于某种原因端口 80 没有监听,尽管网站的配置文件说这样做:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 702/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1211/sshd
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1326/mysqld
tcp6 0 0 :::21 :::* LISTEN 1005/vsftpd
tcp6 0 0 :::22 :::* LISTEN 1211/sshd
当我跑步时nginx -t
,我得到这个:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
当我运行时service nginx status
,我得到以下行以及其他行(其中都不包括“关闭”或“禁用”):
Active: active (running) since Sat 2018-11-24 10:47:48 UTC; 5h 38min ago
所以我知道 nginx 正在运行,配置文件的语法是正确的,特定网站的配置文件说监听端口 80,并且配置文件在 /sites-enabled 中符号链接
答案1
我最终卸载、重新安装并重新配置 nginx。无需重新配置太多内容,只需在anneliesephotos 配置文件中添加几行即可。但这并没有解决问题。
我发现我什至无法从网络外部 ping 该网站。我检查了我的路由器,它说它允许所有流量到达网络服务器,但显然不是。我重新配置了路由器以仅允许我需要的协议。然后我重新启动路由器,它开始让流量通过。
我完成了重新配置 nginx 来为网站提供服务。我也不得不改变
try_files $uri $uri/ =404;
到
try_files $uri $uri/ /index.php?q=$uri&$args;
现在它又可以工作了。