Nginx 正则表达式位置语法
正则表达式可以与 Nginx 位置块部分一起使用,这是通过 PCRE 引擎实现的。
由于没有完整记录,此功能究竟支持什么?
我正在运行 nginx 作为 docker-compose 模板的一部分。在 nginx 配置中,我通过 docker 主机名引用其他服务(例如backend,ui)。在我完成这个技巧之前,这一切都很好:
docker stop backend
docker stop ui
docker start ui
docker start backend
Run Code Online (Sandbox Code Playgroud)
这使得后端和 ui 容器交换 IP 地址(docker 在向每个新请求者提供 CIDR 中的下一个可用 IP 的基础上提供私有网络 IP)。这 4 个命令的执行模仿了一些罕见的情况,即两个上游容器同时重新启动,但 nginx 容器没有重新启动。另外,我相信,在基于 Kubernetes 的集群上运行 pod 时,这应该是一种非常常见的情况。
现在nginx将backend主机解析为ui的IP和ui后端的IP。重新加载 nginx 的配置确实有帮助(nginx -s reload)。另外,如果我从 nginx 容器内进行 nslookup - IP 总是能正确解析。
因此,这将问题隔离为围绕 DNS 缓存的纯粹 nginx 问题。
我尝试过的事情:
resolver 127.0.0.11 ipv6=off valid=10s;
Run Code Online (Sandbox Code Playgroud)
我可以在执行命令时寻求帮助吗 docker-compose up -d
我收到错误你能帮我如何使用 nginx 执行 php
Removing nginx-container
mysql-container is up-to-date
php-container is up-to-date
Recreating 2e6f7b9915c6_nginx-container ... error
ERROR: for 2e6f7b9915c6_nginx-container Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/host_mnt/c/webdock/firstweb/default.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged\\\" at \\\"/var/lib/docker/overlay2/8261a085184069473ca52f3ad508386e84f0636baafbbc754e1447ea72427433/merged/etc/nginx/conf.d\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: for web …Run Code Online (Sandbox Code Playgroud) 如何使用此模块将 Nginx 作为服务启动?
根据这个文档,它说:
默认情况下不构建此模块,应使用 --with-http_sub_module 配置参数启用它。
我不明白在哪里输入这个命令。是nginx service start --with-http_sub_module吗?那太令人困惑了。
当我输入时,nginx -V它显示--with-http_sub_module可用。
我试图将 www 重定向到非 www,但它不起作用。我尝试过类似问题的各种答案,但没有成功。
我使用 certbot 为 3 个域提供了 SSL 证书example.com,www.example.com并且admin.example.com.
这是我当前的配置,适用于非 www 和管理员,但 www.example.com 不起作用。
# HTTP - redirect all requests to HTTPS
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
# Redirect to non-www
server {
server_name www.example.com;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.se/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.se/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
return …Run Code Online (Sandbox Code Playgroud) Nginx 使用 PCRE 引擎来评估正则表达式,文档指出不使用分隔符,因此我们不必像在标准正则表达式中那样/转义 URI 中的正斜杠。/有效的 nginx 正则表达式的示例是location ~* /myapp/.+\\.php$
但以下代码转义了正斜杠
\n\nlocation ~ ^\\/(?:index|core\\/ajax\\/update|ocs\\/v2|ocm-provider\\/.+)\\.php(?:$|\\/)
在这种情况下到底意味着什么\\/?当文档另有说明时为什么需要它?
我在 nginx 错误日志中收到此错误:
SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking
Run Code Online (Sandbox Code Playgroud)
我目前使用 Let's Encrypt。有什么想法可以解决这个问题吗?谢谢你们。
我有两个域(客户端的example.com,rest API的api.example.com),考虑到CORS策略,我从客户端向API请求。预检请求按预期工作,除文件上传外,其他所有请求(GET/POST/PUT/DELTE)都运行良好,这意味着 Content-type 是否为“multipart/form-data”。
我在 Chrome 控制台中收到以下错误:
从源“ https://www.example.com ”访问“ https://api.example.com/video/upload ”处的 XMLHttpRequest已被 CORS 策略阻止:没有“Access-Control-Allow-Origin”标头存在于请求的资源上。
这是我的客户端(vuejs)来源:
var config = {
headers: { "Content-Type": "multipart/form-data" },
onUploadProgress(e) {
if (e.lengthComputable) {
self.percentage = Math.round(e.loaded / e.total * 100) + "%";
}
}
};
axios
.post(apiUrl + `/video/upload`, formData, config)
.then(response => {
this.successes.push(
response.data.videoName + " uploaded."
);
})
.catch(e => {
this.errors.push(message);
});
},
Run Code Online (Sandbox Code Playgroud)
以及 CORS 的 nginx 配置:
server {
listen 443 ssl default_server http2;
listen [::]:443 ssl default_server …Run Code Online (Sandbox Code Playgroud) 我正在使用Ubuntu 18 服务器并使用带有gunicorn 的nginx我按照Digitalocean教程进行服务器设置。我成功完成了一个项目,但现在我需要在服务器下运行多个项目。
这是我的gunicorn 设置
命令:
sudo nano /etc/systemd/system/gunicorn.service
Run Code Online (Sandbox Code Playgroud)
文件:
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=rfr
Group=www-data
WorkingDirectory=/home/rfr/helpdesk/helpdesk
ExecStart=/home/rfr/helpdesk/env/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
helpdesk.wsgi:application
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
这也是我的nginx 设置
命令:
sudo nano /etc/nginx/sites-available/helpdesk
Run Code Online (Sandbox Code Playgroud)
文件:
server {
listen 80;
server_name 192.168.11.252;
location = /favicon.ico { access_log off; log_not_found off; }
location /assets/ {
root /home/rfr/helpdesk/helpdesk;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
} …Run Code Online (Sandbox Code Playgroud) 这在我的 Nginx 配置中有效:
# This works
proxy_pass http://GitLab-CE:9080;
Run Code Online (Sandbox Code Playgroud)
...但这并不:
# does not work
set $upstream_gitlab GitLab-CE;
proxy_pass http://$upstream_gitlab:9080;
Run Code Online (Sandbox Code Playgroud)
这是从使用连字符和不同端口的不同工作示例复制的。
# this works
set $upstream_deluge binhex-delugevpn;
proxy_pass http://$upstream_deluge:8112;
Run Code Online (Sandbox Code Playgroud)
我想也许与破折号有关,但我有另一个配置,它的名称中也使用连字符(见上文)并且它有效。我尝试过各种形式的引用,但似乎都没有帮助。这里可能发生了什么?我很茫然。GitLab-CE 不起作用但 binhex-delugevpn 起作用是怎么回事?Nginx 是否看到 CE 有一些十六进制数学?
完整上下文:
# make sure that your dns has a cname set for gitlab and that your gitlab container is not using a base url
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name gitlab.*;
include /config/nginx/ssl.conf;
client_max_body_size 0;
# enable for ldap auth, fill in ldap …Run Code Online (Sandbox Code Playgroud) nginx-config ×10
nginx ×8
regex ×2
regex-group ×2
certbot ×1
cors ×1
django ×1
docker ×1
file-upload ×1
gunicorn ×1
https ×1
php ×1
ssl ×1