我在 NGINX 上阅读了很多问题,其中不监听端口 80,但我的问题有所不同。 NGINX 监听我的默认端口 80,但是当我尝试更改监听 81 时,NGINX 将监听来自端口 81 的任何请求,但它不会给我任何响应。
无论如何,这就是我所做的。 1.) 我在/etc/nginx/sites-available/myportconfig 中创建一个配置文件 2.)然后我创建了一个符号链接(symbolic link),如下所示 ln -s/etc/nginx/sites-available/myportconfig/etch/nginx/sites-enable/ 3.)我没有修改/etc/nginx/nginx.conf中的任何内容 4.) 最后是我的 myportconfig 的内容
server {
listen 81;
root /mysites/sites1.com;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name 10.100.100.10;
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# remove trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
if (!-d $request_filename)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME /mysites/sites1.com$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
# Restrict .git directories
location ~ /\.git {
deny all;
}
# Restrict all project directories
location ~ /\. {
deny all;
}
}
另请注意,仅使用端口 80 时,站点加载得很好。但是,当我更改为不同的端口时,它不会加载任何页面......我错过了一些东西吗?请帮忙...
我还尝试使用 netstat
netstat -lnp | grep 8
它给了我这个输出
tcp 0 0.0.0.0:81 0.0.0.0:* LISTEN
udp 0 0.0.0.0:68 0.0.0.0:*
我还尝试在服务器内部进行telnet
telnet 10.100.100.10 81
这是回复
Trying 10.100.100.10
connected to 10.100.100.10
Escape character is '^]'.
Connection closed by foreign host.
当我在本地计算机上telnet
时
telnet 10.100.100.10 81
Connecting To 10.100.100.10....Could not open connection to the host, on port 81:
Connection failed
希望有人能帮助我解决这个问题。我想做的是使用不同的端口而不是使用端口 80 访问我的网站
最佳答案
抱歉,如果我没有提到它是 AWS 的一个实例。但我发现 Tan Hong Tat 的想法与这个问题的解决方案有点类似。我发现除了端口 80 和 443 的请求之外,所有来自服务器外部的访问都被阻止。再次感谢大家的回复 – Madzmar Ullang
关于linux - Nginx 监听而不是端口 80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27497481/