Failed to use port:80



  • Hi guys,

    I have been trying to handle this problem several days.

    My site's name is xxx.com.

    I have nginx installed in the server, when I type xxx.com it says:

    0_1460981472482_nginx.JPG

    So that means that nginx is working.

    Then I set it by (in /etc/nginx/sites-available, the file's name is xxx.com😞

    server {
        listen 80;
    
        server_name xxx.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567/;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    Then I ln -s this to sites-enable.

    My nodebb conf is:

    
    {
        "url": "http://xxx.com",
        "secret": "..............................................",
        "database": "redis",
        "redis": {
            "host": "127.0.0.1",
            "port": "6379",
            "password": "",
            "database": "0"
        }
    }
    

    It just does work.

    I can only access my website by xxx.com:4567.

    Any suggestions?

    Thanks.


  • Plugin & Theme Dev

    @sharonyue did you restart nginx after you added the config file in sites-enabled?

    and to also make sure you mentioned you named your config file xxx.com. I believe it has to be a .conf file like xxx.com.conf



  • @pichalite
    Hi,

    yes, I restart nginx by service nginx reload or service nginx restart to restart.

    I name it by xxx.com. After your post, I rename it to xxx.com.conf and ln -s it to sites-enable.

    Does not work...

    when i type, it says: welcome to nginx...


  • Plugin & Theme Dev

    @sharonyue I have not used sites-enabled before so, I am not sure what else to check for that.

    I usually just set the config in /etc/nginx/conf.d/default.conf and then restart nginx



  • @pichalite Hi,

    I just copy this:

    server {
        listen 80;
    
        server_name xxx.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567/;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    into /etc/nginx/conf.d/default.conf . Does not work for me...

    Am I setting it correctly? Actually I have check it many many times, I did not notice any mistake in my code.


  • Plugin & Theme Dev

    @sharonyue did you restart nginx?



  • What Operating System do you use. I use CentOS 6.5 and the configuration file is /etc/nginx/nginx.conf.



  • @Hao-Lee

    Im using ubuntu 14.04. I just tried to copy that to etc/nginx/nginx.conf. Does not work..

    @pichalite Yeah...of course..



  • After some searching, by the following code I can use xxx.com to access:

    echo 1 > /proc/sys/net/ipv4/ip_forward
    iptables -I PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 4567
    

    I have no idea what I did, but this looks PRETTY SIMPLER than Nginx.

    But Is it dangerous? Why nodebb team did not mention this very simple method? just copy these two lines in the terminal. Then it works.

    Thanks guys.



  • @sharonyue I think the purpose using nginx proxy is to prevent your forum from being attacked.


  • Community Rep

    @Hao-Lee nginx is a Reverse Proxy, it lets you run several services on the same port. By itself, it does nothing for security, you need to handle security by setting the config files appropriately, among other measures. 🌈


  • Community Rep

    @sharonyue It's not really a good idea to do port forwarding. It is potentially insecure, you are not setting the appropriate headers, websockets will never work, and you may see other issues in the future.

    Your server config looks correct. Can you post the main config?
    /etc/nginx/nginx.conf



  • @yariplus Thanks for the correction !


  • Admin

    @sharonyue You can do this if you like, but if your server restarts, it will be reset. Nginx provides additional functionality besides simple port forwarding 😄



  • @yariplus

    Hi yariplus,

    Thanks for you explanation. Here are my code in nginx.conf:

    root@iZ94134cujlZ:/etc/nginx# more nginx.conf
    user www-data;
    worker_processes 4;
    pid /run/nginx.pid;
    
    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;
    
            ##
            # Logging Settings
            ##
    
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
    
            ##
            # Gzip Settings
            ##
    
            gzip on;
            gzip_disable "msie6";
    
            # 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/x-javascri
    pt text/xml application/xml application/xml+rss text/javascript;
    
            ##
            # nginx-naxsi config
            ##
            # Uncomment it if you installed nginx-naxsi
            ##
    
            #include /etc/nginx/naxsi_core.rules;
    
            ##
            # nginx-passenger config
            ##
            # Uncomment it if you installed nginx-passenger
            ##
    
            #passenger_root /usr;
            #passenger_ruby /usr/bin/ruby;
    
            ##
            # Virtual Host Configs
            ##
    
            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    }
    
    
    #mail {
    #       # See sample authentication script at:
    #       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
    #
    #       # auth_http localhost/auth.php;
    #       # pop3_capabilities "TOP" "USER";
    #       # imap_capabilities "IMAP4rev1" "UIDPLUS";
    #
    #       server {
    #               listen     localhost:110;
    #               protocol   pop3;
    #               proxy      on;
    #       }
    #
    #       server {
    #               listen     localhost:143;
    #               protocol   imap;
    #               proxy      on;
    #       }
    #}
    
    server {
        listen 80;
    
        server_name xxx.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567/;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    root@iZ94134cujlZ:/etc/nginx#
    

    nginx version: nginx/1.4.6 (Ubuntu)

    Any suggestions are welcome!



  • @sharonyue said in Failed to use port:80:

        proxy_pass http://127.0.0.1:4567/;
    

    Try removing the trailing slash on that line.


  • Community Rep

    @sharonyue Well, I see one big problem, the server blocks need to be inside the http block. Right after the includes is a good place to put them. Should look like below.

    http {
        ...
        server {
            ...
        }
    }
    

    Also, I would comment out the include lines since you are not using them.



  • Hi guys,

    I got this working:

    
    server {
        listen 80;
    
        server_name xxx.com www.xxx.com;
    
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
    
            proxy_pass http://127.0.0.1:4567;
            proxy_redirect off;
    
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
    

    Thank you very much!

    one other thing is that, so by nginx, if my server restart, I dont need to set up nginx again and nginx will start automatically?


  • Admin

    Nginx should start up automatically on system reboot unless you have installed it yourself.


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.