Failed to use port:80

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

  • @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. 🌈

  • @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 !

  • @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.

  • @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?

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


Suggested Topics