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

Install Docker for Windows on Windows 10 Home Edition

0. Background Hardware: Xiaomi Notebook Air 13/In...

How to optimize logic judgment code in JavaScript

Preface The logical judgment statements we use in...

About the role of meta in HTML (collected and sorted from the Internet)

W3Cschool explains it this way The <meta> el...

How to open a page in an iframe

Solution: Just set the link's target attribute...

MySQL uses the Partition function to implement horizontal partitioning strategy

Table of contents 1 Review 2 Five strategies for ...

Vue implements a simple shopping cart example

This article shares the specific code of Vue to i...

HTML web page hyperlink tag

HTML web page hyperlink tag learning tutorial lin...

MySQL 8.0 WITH query details

Table of contents Learning about WITH queries in ...

How to build php+nginx+swoole+mysql+redis environment with docker

Operating system: Alibaba Cloud ESC instance cent...

Example of using CSS to achieve semi-transparent background and opaque text

This article introduces an example of how to use ...

jQuery achieves the shutter effect (using li positioning)

This article shares the specific code of jQuery t...

Detailed explanation of nginx shared memory mechanism

Nginx's shared memory is one of the main reas...

Detailed explanation of the use of the clip-path property in CSS

Use of clip-path polygon The value is composed of...

How to build your own Nexus private server in Linux

This article describes how to build a Nexus priva...