在这里,我两个应用程序都有nginx配置。
您可以在需要帮助的地方看到我的评论。
upstream node1 {
server localhost:2053;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
# ssl on;
ssl_certificate /home/ubuntu/CA/cert/mycert.pem;
ssl_certificate_key /home/ubuntu/CA/key/mykey.key;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name myPublicIP;
location / {
root /home/ubuntu/app1/public;
index index.html index.htm
proxy_pass https://localhost:8443;
try_files $uri $uri/ =404;
}
location ~* ^.+\.(jpg|jpeg|gif|mp3|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$ {
//Here I need create root for two apps,which are in defferent paths
//1st in /home/ubuntu/app1/public and second in /home/ubuntu/app2/public
}
location /users/register {
root /home/ubuntu/app1/public;
index index.html index.htm;
proxy_pass https://localhost:8443/users/register;
}
location /users/authenticate {
root /home/ubuntu/app1/public;
index index.html index.htm;
proxy_pass https://localhost:8443/users/authenticate;
}
location /users/home {
root /home/ubuntu/app1/public;
index index.html index.htm;
proxy_pass https://localhost:8443/users/home;
}
location /game {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
root /home/ubuntu/app2/public;
index index.html index.htm;
proxy_pass https://node1/;
}
在这里,我需要设置类似脚本的内容,以查找位置是否为/ game /以便从运行在不同端口上的app2提供静态文件。对于其他位置,服务器必须提供来自app1的静态文件。没有nginx都可以正常工作。我如何解决此问题。感谢您的帮助和关注。
最佳答案
如果我做对了,那么当用户位于/ game /网址中时,您需要从/ home / ubuntu / app2 / public提供静态文件,而在其他地方则需要从/ home / ubuntu / app1 / public提供静态文件。我说对了吗?
如果是这样,您应该制作两个不同的location
,就像您已经写的一样。就像是
location ~* ^\/game\/(.+\.(jpg|jpeg|gif|mp3|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm))$ {
root /home/ubuntu/app2/public;
try_files $1 $1/ =404;
}
location ~* ^(.+\.(jpg|jpeg|gif|mp3|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm))$ {
root /home/ubuntu/app1/public;
try_files $1 $1/ =404;
}
这未经测试,但应该可以完成。