How to set Nginx to forward the domain name to the specified port

How to set Nginx to forward the domain name to the specified port

Enter /usr/local/nginx/conf

sudo cd /usr/local/nginx/conf

Create vhost directory

sudo mkdir vhost

Modify the nginx.conf file

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

Set the hosts file of the access machine to simulate access. The machine I use here is Windows 10, and the hosts file is in the C:\Windows\System32\drivers\etc folder.

Create a port proxy configuration file

sudo cd vhost
sudo vim www.jaydenmall.com.conf
server {
	# Listen to port 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 ~* ".*[\;'\<\>].*" ){
    return 404;
  }
  location / {
    # Reverse proxy to port 8080 proxy_pass http://127.0.0.1:8080;
    add_header Access-Control-Allow-Origin *;
  }
}

Restart nginx

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

Errors may occur, in which case you need to use the nginx -c parameter to specify the location of the nginx.conf file.

sudo killall -9 nginx # Kill nginx process sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
sudo ../../sbin/nginx -s reload # Restart

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

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of Nginx domain name forwarding
  • Using nginx forward proxy to implement intranet domain name forwarding process analysis
  • Nginx reverse proxy is used for intranet domain name forwarding
  • Implementation of HTTP and HTTPS services with Nginx reverse proxy for multiple domain names
  • Use nginx + secondary domain name + https support
  • Nginx defines domain name access method
  • nginx+tomcat example of accessing the project through the domain name
  • Nginx domain forwarding usage scenario code example

<<:  MySQL 8.0 installation tutorial under Linux

>>:  JavaScript to implement simple tab bar switching content bar

Recommend

Detailed usage of Vue more filter widget

This article example shares the implementation me...

The pitfalls encountered when learning Vue.js

Table of contents Class void pointing ES6 Arrow F...

Code to enable IE8 in IE7 compatibility mode

The most popular tag is IE8 Browser vendors are sc...

Detailed explanation of the definition and function of delimiter in MySQL

When you first learn MySQL, you may not understan...

TypeScript namespace explanation

Table of contents 1. Definition and Use 1.1 Defin...

MySQL multi-master and one-slave data backup method tutorial

Overview Operations on any one database are autom...

Complete steps to use mock.js in Vue project

Using mock.js in Vue project Development tool sel...

Binary Search Tree Algorithm Tutorial for JavaScript Beginners

Table of contents What is a Binary Search Tree (B...

Several methods to clear floating (recommended)

1. Add an empty element of the same type, and the...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

Detailed explanation of the difference between Vue life cycle

Life cycle classification Each component of vue i...