我在/etc/nginx/sites-enabled/wildcard.dev.example.net上有一个文件。
此文件位于开发人员环境中,因此我在下一行中动态加载了文件夹:
server_name ~^(?<folder>[^.]*).dev.example.net;
root /home/foobar/Desktop/Projects/$folder/web;
因此,如果我添加一个名为test的文件夹,则可以通过http://test.dev.example.net访问此文件夹 现在我需要添加具有以下结构的websocket ws://socket.test.dev.example.net
所以我试图弄清楚我该如何实现...
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server 127.0.0.1:80;
}
server {
listen 80;
server_name ~^(?<folder>[^.]*).dev.example.net;
charset utf-8;
index index.php index.html index.htm;
root /home/foobar/Desktop/Projects/$folder/web;
error_log /home/foobar/Desktop/Projects/logs/files/access.log;
error_log /home/foobar/Desktop/Projects/logs/files/error73.log;
client_max_body_size 6000M;
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|js|css)$ {
access_log off;
log_not_found off;
expires 30d;
add_header Pragma "public";
}
location / {
try_files $uri @rewriteapp;
proxy_pass http://socket.$folder.dev.example.net:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
location @rewriteapp {
# rewrite all to app.php
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV magana;
fastcgi_param HTTPS off;
}
location ~ /\.ht {
deny all;
}
}
有什么想法吗? 谢谢