Home  >  Article  >  Operation and Maintenance  >  How to set up Nginx domain name forwarding to a specified port

How to set up Nginx domain name forwarding to a specified port

PHPz
PHPzforward
2023-05-14 21:37:121937browse

Enter /usr/local/nginx/conf

sudo cd /usr/local/nginx/conf

Create the vhost directory

sudo mkdir vhost

Modify the nginx.conf file

sudo cp nginx.conf nginx.conf_back
sudo vim nginx.conf

How to set up Nginx domain name forwarding to a specified port

Set the hosts file of the access machine to simulate access. The machine I am using here is Windows 10. The hosts file is in the c:\windows\system32\drivers\etc folder.

How to set up Nginx domain name forwarding to a specified port

Create port proxy configuration file

sudo cd vhost
sudo vim www.jaydenmall.com.conf
server {
	# 监听 80 端口
  listen 80;
  autoindex on;
  server_name www.jaydenmall.com;
  access_log /usr/local/nginx/logs/access.log combined;
  index index.html index.htm index.jsp index.php;
  if ( $query_string ~* ".*[\;&#39;\<\>].*" ){
    return 404;
  }
  location / {
    # 反向代理到 8080 端口
    proxy_pass http://127.0.0.1:8080;
    add_header access-control-allow-origin *;
  }
}

Restart nginx

sudo ../../sbin/nginx -s reload

There may be errors, in which case you need to use nginx The -c parameter specifies the location of the nginx.conf file.

How to set up Nginx domain name forwarding to a specified port

sudo killall -9 nginx # 杀掉 nginx 进程
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
sudo ../../sbin/nginx -s reload # 重启

The port reverse proxy is successful. Note that the red part is the default port 80, which actually points to port 8080 of tomcat.

How to set up Nginx domain name forwarding to a specified port

The above is the detailed content of How to set up Nginx domain name forwarding to a specified port. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete