How to solve the problem that Vue deployment to online forwarding does not take effect

PHPz
Release: 2023-04-12 10:22:42
Original
1150 people have browsed it

Vue.js is a popular front-end framework. During the development process, we usually deploy Vue.js front-end applications to cloud servers. However, after deployment, sometimes we encounter the problem that forwarding does not take effect. So, how to solve the problem that Vue deployment to online forwarding does not take effect?

1. Check the Nginx configuration

The first step is to check whether the Nginx configuration is correct. In the Nginx configuration, we need to configure the path to be forwarded as location and specify the proxy server and port. For example:

server { listen 80; server_name example.com; location /api/ { proxy_pass http://localhost:3000; } }
Copy after login

The above configuration means forwarding all requests underexample.com/api/to the local port 3000.

2. Check the Vue code forwarding configuration

In addition to the Nginx configuration, you also need to check the Vue code forwarding configuration. In thevue.config.jsfile, we need to configure the path to be forwarded as theproxyoption, and also specify the proxy server and port. For example:

module.exports = { devServer: { proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true, pathRewrite: { '^/api': '' } } } } }
Copy after login

The above configuration means that all requests under/apiwill be forwarded to the local port 3000, and/apiwill be removed from the request path. This is achieved The purpose of request forwarding.

3. Check the firewall settings

If the above two methods fail to solve the problem, we also need to check the firewall settings of the cloud server. Sometimes, the firewall settings of the cloud server restrict access to certain ports, making our forwarding service inaccessible from outside the server. Checking the firewall settings requires logging in to the cloud server. Taking CentOS as an example, execute the following command:

systemctl status firewalld
Copy after login

If the firewall is not enabled, port access will not be restricted. If the firewall is enabled, port opening settings are required. Taking port 3000 as an example, execute the following command:

sudo systemctl start firewalld # 启用防火墙 sudo firewall-cmd --permanent --add-port=3000/tcp # 开放 3000 端口 sudo firewall-cmd --reload # 重启防火墙 sudo firewall-cmd --list-all # 查看已开放端口
Copy after login

The above command will open port 3000 so that external servers can access our forwarding service.

Summary

The above are three methods to solve the problem that Vue deployment to online forwarding does not take effect. During the actual development process, we need to check Nginx, Vue code and cloud server firewall settings at the same time. Through the above series of operations, we can successfully deploy the Vue.js application and implement request forwarding.

The above is the detailed content of How to solve the problem that Vue deployment to online forwarding does not take effect. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!