Home > Operation and Maintenance > Nginx > What is the method to solve nginx pointing to local path and 500 error?

What is the method to solve nginx pointing to local path and 500 error?

WBOY
Release: 2023-05-27 09:22:12
forward
1483 people have browsed it

A vite vue3 project that I want to deploy to the server. The files after the project is built are all in the dist directory. Copy this directory to the server, and then configure it in nginx, as follows:

server {
    listen       3571;
    server_name  localhost;
    location / {
        root /root/xxxx/dist/;
        try_files $uri $uri/ /index.html;
    }
}
Copy after login

In this way, you can access this vue through the server's public IP port 3571 If you want to access the project through the domain name, you can configure it like this:

server {
    listen       80;
    server_name  video.xxx.com;
    location / {
        root /root/xxxx/dist/;
        try_files $uri $uri/ /index.html;
    }
}
Copy after login

In this way, you can directly access the vue project by accessing video.xxx.com directly.

Note that there may be a problem here, that is, a 500 error occurs during access after the configuration is correct. If you encounter this error, first check whether the local path is set correctly. If the path is correct, there may be a permission problem. The nginx user will be configured at the beginning of nginx, as follows:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
...
Copy after login

My default is the nginx user, so there is no permission to access the /root/xxxx/dist/ directory, so a 500 error occurs, change to root Users can do this, as follows:

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
...
Copy after login

Note: After reconfiguring nginx, you need to restart the nginx service (service nginx restart).

The above is the detailed content of What is the method to solve nginx pointing to local path and 500 error?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template