为statis vuejs网站配置nginx

时间:2018-09-11 20:25:11

标签: nginx vue.js server web-deployment centos7

我一直在尝试配置我的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" "-"

1 个答案:

答案 0 :(得分:0)

我不是nginx专家,但是我们有一个运行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;
    }

}