为静态vuejs站点配置nginx

k2arahey  于 2022-12-17  发布在  Nginx
关注(0)|答案(2)|浏览(133)

我一直在尝试配置我的nginx vuejs静态前端。我的网站总是返回一个500。我基于我的/etc/nginx/nginx.conf文件this site
当我转到指定的ip_address时,返回500屏幕,具体返回500 Internal Server Error nginx/1.12.2
它为什么要这么做呢?我知道根文件路径是正确的,但它似乎找不到它。

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  floating_ip_address;
    root         ~/frontendFolder;
    index        index.html

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
         try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
         rewrite ^(.+)$ /index.html last;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

编辑:
最新日志如下:

ip - - [12/Sep/2018:16:39:59 +0000] "GET /phpmyadmin-old/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:00 +0000] "GET /phpMyAdminold/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:00 +0000] "GET /phpMyAdmin.old/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:03 +0000] "GET /pma-old/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:03 +0000] "GET /claroline/phpMyAdmin/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:05 +0000] "GET /typo3/phpmyadmin/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:07 +0000] "GET /phpma/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:07 +0000] "GET /phpmyadmin/phpmyadmin/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:40:15 +0000] "GET /phpMyAdmin/phpMyAdmin/index.php HTTP/1.1" 200 3700 "-" "Mozilla/5.0" "-"
ip - - [12/Sep/2018:16:44:37 +0000] "GET / HTTP/1.1" 200 3700 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7" "-"
ip - - [12/Sep/2018:16:47:28 +0000] "GET / HTTP/1.1" 500 595 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36" "-"
jq6vz3qz

jq6vz3qz1#

我的Vue项目也有同样的问题,我100%确定我的nginx服务器块是好的。* 下面是一个例子:*

server {
listen      80;
server_name example.com www.example.com;        charset utf-8;
root    /var/www/myapp/dist;
index   index.html;
#Always serve index.html for any request
location / {
    root /var/www/myapp/dist;
    try_files $uri  /index.html;
}
error_log  /var/log/nginx/vue-app-error.log;
access_log /var/log/nginx/vue-app-access.log;
}

但是,我得到了错误500。我也分配执行权限到**dist/**文件夹和nginx用户所有权的文件:

chown -R www-data:www-data ./dist/*

以及

chmod 755 -R ./dist/*

解决方案

检查www数据用户是否有路径/文件许可

root@root:# sudo -u www-data stat /home/myuser/public_html/

输出:

sudo:/etc/sudo.conf是可组写的sudo:/etc/sudo.conf是组可写文件:/home/公共页面/大小:4096
数据块:8个IO数据块:4096目录设备:第01 h/64513 d号
信息节点:258318链接:4访问权限:(0775/drwxrwxr-x)用户ID:(0/
root)GID:(0/ root)访问权限:2022年12月7日13时48分55秒245310115 + 0000修改时间:2022年12月6日13:13:40.187999036 +0000修改时间:2022年12月7日13:48:33.149826680 + 0000出生日期:2022年12月6日07时34分49.277257817秒
如果www-data没有权限,那么给他分配组/权限,在我的情况下,我把他添加到根用户组

sudo adduser www-data root

一切都结束了。

xoshrz7s

xoshrz7s2#

我不是nginxMaven,但我们有一个运行nginx的生产服务器来服务一个静态Vue网站,并代理API和WebSocket请求到一个运行在8200端口上的Butterfly Server .NET。
不管怎样,这是我们的nginx配置文件,希望它能帮助...

server {
    listen                      80;
    listen          [::]:80;
    server_name                 my.mysite.com;
    root                        /opt/mysite/my;
    return 301 https://my.mysite.com$request_uri;
}

server {
    listen          443 default_server ssl;
    server_name                 my.mysite.com;
    ssl_certificate     /opt/mysite/ssl/my_mysite_io.bundle.crt;
    ssl_certificate_key     /opt/mysite/ssl/my_mysite_io.key;
    root                        /opt/mysite/my;
    client_max_body_size        128000000;

    # index
    index index.html;

    # $uri, index.html
    location / {
        try_files $uri $uri/ /index.html;
    }

    location ~* \.(?:jpg|jpeg|png|ico)$ {
        expires 1y;
        add_header Cache-Control "public";
        access_log off;
    }

    location /index.html {
        expires -1;
        add_header Cache-Control "no-cache, public, must-revalidate, proxy-revalidate";
    }

    location /api {
        proxy_pass http://127.0.0.1:8200;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

    location /ws {
        proxy_pass http://127.0.0.1:8200;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

}

相关问题