Failed to use port:80
-
@pichalite
Hi,yes, I restart nginx by
service nginx reload
orservice 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...
-
@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.
-
@sharonyue did you restart nginx?
-
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.
-
-
@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
-
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 thehttp
block. Right after theinclude
s 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?