Articles of nginx

Nginx的代理重写与条件为域

我处于一个相当未知的情况,但我相信可以使用nginx代理和URL重写function来完成。 我想要的是: 有一个网站有多个品牌,所以我们说我有3个域名。 因此,如果有人试图访问domain1.com,nginx会将徽标URL重写为logo1.png。同样适用于: Domain2.com> logo2.png Domain2.com> logo3.png 我知道有可能为同一个文件提供3个域名。 这是我所做的: #domain1.com nginx_conf server { listen 80 default_server; root /var/www/vhosts/domain1.com/httpdocs/; index index.php index.html index.htm; server_name domain.com domain1.com; location / { sub_filter '<img src="/images/logo.png' 'img src="/images/logo1.png'; try_files $uri $uri/ /index.php; } 如果我有三个独立的configuration,你认为这会起作用吗? 让我知道。 谢谢。 的Shahriar

Nginx的X-Accellredirect给502坏的网关

我想允许用户从远程存储下载文件,但我想先通过我的Rails应用程序validation请求。 当railsvalidation请求时,我想把远程文件的代理移交给nginx,释放ruby / rails线程。 我有这个名为proxy_download.conf的nginx conf文件: # Proxy download location ~* ^/internal_redirect/(.*?)/(.*) { # Do not allow people to mess with this location directly # Only internal redirects are allowed internal; # Location-specific logging access_log logs/internal_redirect.access.log combined; error_log logs/internal_redirect.error.log warn; # Extract download url from the request set $download_uri $2; set $download_host $1; # Compose […]

Ngin,url:/ search =>运行php /search.php和url:/ my => php my.php

请帮我configurationNginx: 1)我有一些PHP脚本,我想运行他们的URL没有“.php”例如 url / search – >运行脚本“/search.php” url / bookmark – >运行脚本“/bookmarks.php” url / – >运行脚本“/index.php” 2)404 / asdfasdfasdf – 任何不匹配任何指定的位置,不会导致静态文件(图像,CSS)应该运行/not-found.php保存/ asdfasdfasdf在URL 当前服务器节根目录/ var / www / site / public; index index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ \.(ico|css|js|jpe?g|png)$ { expires 7d; add_header Pragma public; […]

Gunicorn根视图不再适用于SSL nginx代理

我有一个Django项目,显示根目录上的login视图。 这是url模式: url(r'^$', views.login_view, name="root_login") 这工作在一个未encryption的连接:当我在浏览器中访问http://example.com ,我得到我的login模板。 我最近使用letsencrypt在我的nginx代理上安装了SSL证书。 现在,当我尝试https://example.com我得到“Welcome to nginx!” 页。 当我使用不同的URL模式(例如, https://example.com/login )时,应用程序服务器按预期呈现视图。 实际上,除了根目录以外,所有的应用程序服务器视图都可以工 所以我猜我的location /上下文在我的SSL服务器块的nginxconfiguration是错误的,但我不明白在哪里,因为它是完全相同的location /上下文在我的未encryption的80端口块,它的工作原理。 这是整个SSL块 – 我的错误在哪里? server { #SSL connection listen 443; ssl on; server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_dhparam /etc/ssl/certs/dhparam.pem; ssl_ciphers #omitted for brevity; ssl_session_timeout 1d; ssl_session_cache shared:SSL:1m; ssl_stapling on; ssl_stapling_verify […]

将服务器映射到nginx中的域指令

我想知道是否有可能将一个域指令映射到服务器。 在我们的例子中,我们有一个由Rails实例提供的api,然后我们有一个从Node服务器提供的前端。 理想情况下,我希望前端http://domain.com/ *和API到http://domain.com/api *,但这甚至有可能吗? 我尝试了以下(只是一个片段)。 # Configuration for API. server { server_name www.domain.com/api; location /api { try_files $uri @proxy; } …. } # Configuration for the server server { server_name www.domain.com; location / { try_files $uri @proxy; } …… } 然而,这似乎并没有工作,甚至有可能得到所需的? 或者我需要其中的一个在子域上运行?

打开构build系统错误,在Ubuntu 16.04存储库中没有提供dh-systemd(> = 1.5)

我正在尝试为Ubuntu 16.04构build一个自定义nginx包[链接到我的项目] 。 我创build了我的gpg签名file upload使用命令代码: debuild -S -sa -k'mygpgkey' 并上传 nginx_1.8.0-1ppa〜xenial.debian.tar.xz,nginx_1.8.0-1ppa〜xenial.dsc,nginx_1.8.0-1ppa〜xenial_source.build,nginx_1.8.0-1ppa〜xenial_source.changes,nginx_1.8.0.orig。 tar.xz 在Ubuntu 16.04的file upload仓库显示了一个不受保护的错误,“ 没有提供dh-systemd(> = 1.5) “后来我把init-system-helper包也包含进来了 的.dsc 文件,但没有帮助。 如果有人可以请帮我,我怎样才能得到dh-systemd(> = 1.5)安装在我的Ubuntu 16.04库的testing机器,那么这将是一个很大的帮助。 先谢谢你。

68个并发用户访问网站后发生502个网关错误

我在jMeter中进行一些压力testing时遇到了问题。 基本上,我们正在达到68个并发用户的硬性限制。 一旦testing达到这个数量的用户,我们得到502坏的网关错误。 有趣的是,我们得到了68个虚拟机用户和CPU和RAM两倍的故障。 所以这让我相信这是一个configuration问题。 毕竟,每台服务器上的Docker容器之间的configuration是相同的。 我已经尝试提高nginx.conf中的worker_connections设置,但是没有任何效果。 我什至重新启动机器,以确保新的设置被应用。 有什么其他的想法来看看或尝试什么? 我不知道这是否有帮助,但这是我们在nginx服务器上的configuration失败… upstream unicorn_server { server unix:/app/tmp/unicorn.sock fail_timeout=0; keepalive 512; } server { listen 4043 ssl; ssl_certificate /etc/nginx/certs/hive.crt; ssl_certificate_key /etc/nginx/certs/hive.key; gzip on; gzip_min_length 1000; gzip_proxied expired no-cache no-store private auth; gzip_types application/json; root /app/public; try_files $uri @unicorn_server; keepalive_timeout 10; location @unicorn_server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host […]

负载均衡器显示错误404页面

我有以下configuration: upstream backend { server xx.azurewebsites.net; server xxx.azurewebsites.net; } server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; server_name_; location / { proxy_pass http://backend; } } 问题是请求总是返回一个错误404页面: https : //i.gyazo.com/cb0b81014aac8ea979ad77b246c79377.png 通过浏览器访问xx.azurewebsites.net或xxx.azurewebsites.net工作,但不通过负载平衡器时。 除了azurewebsites.net,我也尝试了其他网站,他们也显示4040页面。 有人知道我在这里错过了什么吗? nginx.conf: user Azureuser; // I changed the user from www-user to Azureuser, did't help though worker_processes auto; pid /run/nginx.pid; events { […]

设置nginx proxy_pass按照使用的协议遵循正确的

我有下面的configuration location / { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } 但是,在应用程序的backend ,有一些使用http协议的path,一些使用httpspath。 我想设置nginx,以便它能正确转发,而不需要在nginx上设置ssl。 这可能吗?

PHP的错误似乎很忙(你可能需要增加pm.start_servers,或pm.min / max_spare_servers)

我在我的专用服务器中使用了ubuntu 15.04,其中有40个cpu核心和160GB的RAM,其中一个stream量大的wordpress站点正在运行。 我使用Nginx作为Web服务器和清漆作为caching服务器。 我的php5-fpm.conf设置是: listen = 127.0.0.1:7654 pm = dynamic pm.max_children = 500 pm.start_servers = 80 pm.min_spare_servers = 20 pm.max_spare_servers = 160 pm.max_requests = 1000 但它仍然显示错误: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 17 idle, and 92 total children WARNING: [pool www] server reached pm.max_children […]