Home > Operation and Maintenance > Nginx > 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
Release: 2023-05-14 21:37:12
forward
2084 people have browsed it

Enter /usr/local/nginx/conf

sudo cd /usr/local/nginx/conf
Copy after login

Create the vhost directory

sudo mkdir vhost
Copy after login

Modify the nginx.conf file

sudo cp nginx.conf nginx.conf_back
sudo vim nginx.conf
Copy after login

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
Copy after login
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 *;
  }
}
Copy after login

Restart nginx

sudo ../../sbin/nginx -s reload
Copy after login

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 # 重启
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template