对于Nginx我有一个很奇怪的问题,我无法从我的浏览器访问它。
我在我的电脑上安装了一个CentOS 7虚拟机,安装并configuration了Nginx,PHP-FPM和MariaDB。
Nginx的configuration如下:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /path/to/www index index.php; try_files $uri $uri/ /index.php?$args; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; try_files $uri $uri/ = 404; root /path/to/www/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
我还configuration了以下规则的iptables:
INPUT_ZONES all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere REJECT all -- anywhere anywhere reject-with icmp-host-prohibited ACCEPT tcp -- anywhere anywhere tcp dpt:http ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere tcp dpt:mysql Chain OUTPUT (policy ACCEPT) target prot opt source destination OUTPUT_direct all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere tcp spt:http ACCEPT tcp -- anywhere anywhere tcp spt:https ACCEPT tcp -- anywhere anywhere tcp spt:mysql
而且我还决定暂时禁用SELinux …
为了完成,当执行“tcpdump端口80”时,我试图访问Web服务器时得到这个消息:
listening on enp0s3, link-type EN10MB (Ethernet), capture size 65535 bytes 19:39:51.574889 IP 192.168.56.1.59338 > 192.168.56.101.http: Flags [S], seq 2033938019, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 551897257 ecr 0,sackOK,eol], length 0
而我的电脑网页浏览器说,它无法连接到指定的服务器…
你有什么想法可能会导致这个问题? 我错过了什么 ?
对不起,这个长信息,但我真的不知道该怎么做..
谢谢
您的防火墙规则拒绝所有传入stream量。
您试图通过手动附加规则来处理这个问题,以允许HTTP,HTTPS和MySQL连接,但这是行不通的,因为它们已经被以前的规则拒绝了。
此外,你的系统正在运行firewalld。
要解决这个问题,你应该使用firewalld来pipe理你的防火墙规则。
例如:
firewall-cmd --add-service=http firewall-cmd --add-service=https firewall-cmd --add-service=mysql
为了让他们坚持下去,运行:
firewall-cmd --runtime-to-permanent
(这最后要求你已经更新到至lessCentOS 7.1。)
我运行centos7并遇到同样的问题,我安装nginx后。 虽然nginx正在运行,但是从broswer访问,我从这个post解决了。
运行以下命令以允许HTTP和HTTPS通信
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload