简体   繁体   English

Nginx监听NOT端口80

[英]Nginx listen to NOT port 80

I have read many issues here on NGINX where in it does not listen to port 80, but my problem is different. 我在NGINX上读过许多问题,其中它不监听端口80,但是我的问题有所不同。 NGINX listens to my default port 80 but when I try to change the Listen 81, so that NGINX will listen to any request coming from port 81 it does not give me any response. NGINX侦听我的默认端口80,但是当我尝试更改“侦听81”时,NGINX将侦听来自端口81的任何请求,但不会给我任何响应。

Anyways here's what I did. 无论如何,这就是我所做的。 1.) I create a config file inside /etc/nginx/sites-available/myportconfig 2.) then I created a symlink like so ln -s /etc/nginx/sites-available/myportconfig /etch/nginx/sites-enable/ 3.) I did not modify anything in /etc/nginx/nginx.conf 4.) And lastly here's the content of my myportconfig 1.)我在/ etc / nginx / sites-available / myportconfig内创建一个配置文件2.)然后我创建了一个符号链接,如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;
        }
}

Also take note that when using only port 80 the sites load just fine. 另请注意,仅使用端口80时,站点加载就很好。 BUt when I change to different port then it does not load any page... am I missing something guys? 当我更改为其他端口时,BUT不会加载任何页面...我在想什么吗? please help... 请帮忙...

I also tried doing netstat with 我也尝试用

netstat -lnp | grep 8

and it gives me this output 它给了我这个输出

   tcp   0   0.0.0.0:81        0.0.0.0:*       LISTEN
   udp   0   0.0.0.0:68        0.0.0.0:*

I also tried doing telnet inside the server 我也尝试在服务器内部进行telnet

   telnet 10.100.100.10 81

and here's the response 这是回应

    Trying 10.100.100.10
connected to 10.100.100.10
Escape character is '^]'.
Connection closed by foreign host.

When I telnet on my local computer 当我在本地计算机上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

Hope someonne can help me with this. 希望someonne可以帮助我。 What I would like to do is access my site using different port and not using port 80 我想做的是使用其他端口访问我的网站,而不是使用端口80

Sorry if I failed to mentioned that Its an instance of AWS. 抱歉,如果我未能提及它是AWS的实例。 But I found out that Tan Hong Tat idea was kinda of a similar solution to the problem. 但是我发现,谭洪达的想法有点类似于解决这个问题。 I found out that all access coming outside the server are being blocked except for request of port 80 and 443. Thanks again for the reply guys – Madzmar Ullang 我发现除了端口80和443的请求之外,所有来自服务器外部的访问都被阻止。再次感谢您的答复– Madzmar Ullang

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM