Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to serve the site with nginx #64

Closed
roddc opened this issue Oct 25, 2021 · 2 comments
Closed

Trying to serve the site with nginx #64

roddc opened this issue Oct 25, 2021 · 2 comments

Comments

@roddc
Copy link

roddc commented Oct 25, 2021

I tried to use nginx to serve the static files, the parent index.html displayed correctly. However, when I navigated to sub-directory, the browser get the wrong assets path, and I got this error in console Uncaught SyntaxError: Unexpected token '<'.

For example: The site displayed correctly when I navigated to http://localhost:8081/guides/zh/, but not http://localhost:8081/guides/zh/sub/; I have to add index.html(http://localhost:8081/guides/zh/sub/index.html) at the end of path manually then it will display correctly.

nginx configuration:

`server {
gzip on;
gzip_min_length 1k;
gzip_comp_level 9;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-
httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_disable "MSIE [1-6].";

listen 80;
server_name localhost;
root /usr/share/nginx/my-site;
autoindex on;

#Another project
location /en-US/ {
    try_files $uri$args $uri$args/ /en-US/index.html;
}

location /zh/ {
    try_files $uri$args $uri$args/ /zh/index.html;
}

location / {
    add_header Cache-Control "no-store";
	try_files $uri$args /zh/index.html;
}
#mkdocs
location /guides/ {
    autoindex off;
	try_files $uri /guides/index.html;
    
    location /guides/zh/ {
        autoindex off;
        try_files $uri /guides/zh/index.html;
    }
}


error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/my-site/zh;
}

}
`
Is there any documentations that can help? Thanks.

@roddc
Copy link
Author

roddc commented Oct 26, 2021

I fixed it, I missed $uri/ in the try_files.

@roddc roddc closed this as completed Oct 26, 2021
@ultrabug
Copy link
Owner

I'm glad you found the solution, happy hosting @roddc :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants