quickly config your ip address port in server host

241 Views
1 Comment

共计 1005 个字符,预计需要花费 3 分钟才能阅读完成。

problem

when I finish my website and start to share my website, I found need Input port number, for example, I input www.dgstudyblog.top:8080 , I want to input site exclude 8080.

use nginx for redirect network , you can follow this;

install nginx

sudo apt update
sudo apt install nginx

enable nginx and start it

sudo systemctl start nginx
sudo systemctl enable nginx

config nginx

nginx usually in /etc/nginx/nginx.conf

use vim to edit;

sudo vim /etc/nginx/nginx.conf

type these into conf , should under http block;

 server {
   listen 80;
  server_name  www.dgstudyblog.top;
  index  index.php index.html index.htm;

  location / {
    proxy_pass  http://127.0.0.1:8080; # 转发规则
    proxy_set_header Host $proxy_host; # 修改转发请求头,让8080端口的应用可以受到真实的请求
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  location ~ ^/(.*)$ {  
        proxy_pass http://127.0.0.1:8080/$1;  
        proxy_set_header Host $host;  
        proxy_set_header X-Real-IP $remote_addr;  
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    }  
}

restart

sudo nginx -s reload
sudo systemctl restart nginx

visit

you can input www.dgstudyblog.top without port 8080

congratulations

END
 0
Comment(1 Comment)