Articles of nginx

PHP7.0-FPM和Nginx不能使用unix套接字

我有一个麻烦,没有在networking上描述。 我正在使用VPS Debian 8 Nginx + PHP7.0-FPM 。 我的服务器在源代码中提供了php文件,当我configurationNginx和PHP7.0-FPM使用unix套接字 (我这样做,因为我读它工作得更快,然后TCP连接),它不编译。 所以我真的做了什么,这是行不通的 : 编辑/etc/nginx/fastcgi_params来注释fastcgi_pass参数使用unix套接字文件: #fastcgi_pass 127.0.0.1:9000; 我所有的主机都包含这个文件,所以我需要在每个主机文件中configuration自己的套接字。 我这样做: 编辑/etc/nginx/sites-available/example.com我在那里inputfastcgi_pass参数 location ~ '\.php$|^/update.php' { fastcgi_split_path_info ^(.+?\.php)(|/.*)$; fastcgi_pass unix:/var/run/php/example.com.php7.0-fpm.conf; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/example.com/www$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/example.com/www; fastcgi_param PHP_ADMIN_VALUE upload_tmp_dir=/var/www/example.com/tmp/upload; fastcgi_param PHP_ADMIN_VALUE session.save_path=/var/www/example.com/tmp/sessions; } 编辑主php7.0-fpm池文件/etc/php/7.0/fpm/pool.d/www.conf来监听套接字(但现在我不明白为什么我需要在这里): listen = /var/run/php/php7.0-fpm.sock 编辑我的网站的池文件/etc/php/7.0/fpm/pool.d/example.com.conf设置它自己的套接字(所以这里有必要,我想): listen = /var/run/php/example.com.php7.0-fpm.sock 重启服务: 服务nginx重启&&服务php7.0-fpm重启 所以这得到我的index.php下载,因为它是当我访问任何网站页面。 但是如果我使用tcp socket fastcgi_pass […]

Nginx X-Frame选项,Iframe WordPress

在Nginx上使用Wordpress。 我收到这些错误,但我似乎无法find我的Nginx选项,我已经指定这个“DENY”标题。 Multiple 'X-Frame-Options' headers with conflicting values ('SAMEORIGIN, DENY') encountered when loading 'https://beta.com/wp-admin/plugin-install.php?tab=plugin-information&plugin=duplicate-post&'. Falling back to 'DENY'. Refused to display 'https://beta.com/wp-admin/plugin-install.php?tab=plugin-information&plugin=duplicate-post&' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN, DENY'. load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils,jquery-ui-core,jquery-ui-widget,jquery…:2 Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Sandbox access violation: Blocked a frame at "https://beta.com" from accessing a frame […]

Nginx – 用重写的URL填充REQUEST_URI

我有一个Nginxconfiguration,用于一个新的PHP应用程序,它具有与另一个传统PHP应用程序相同的function,但具有不同的URL。 我想保留旧应用程序的path,用/pagereplace/foopath前缀,并用/page/otherBarreplace特殊path/foo/bar : # legacy support location ~ ^/foo/bar { rewrite /foo/bar /page/otherBar$1 last; } # How to rewrite all other pages starting with "/foo" ? # END legacy support location / { # try to serve file directly, fallback to front controller try_files $uri /index.php$is_args$args; } location ~ ^/index\.php(/|$) { proxy_read_timeout 300; include fastcgi_params; […]

Nginx – 总是返回403状态码

我试图让Nginx返回一个简单的网页,但总是有一个HTTP状态码403。出于某种原因,我只是不能得到它的工作。 我在/ var / www / html /中有两个文件: 的index.html photo.jpg index.html与photo.jpg一起显示一些文本 这是我的Nginxconfiguration: server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { return 403; } error_page 404 /index.html; error_page 403 /index.html; location = /index.html { allow all; } location = /photo.jpg { allow all; } } […]

在负载平衡器中设置HTTP标头是否是一个好习惯?

我正在pipe理一个设置,在nginx反向代理之后有两个ngnix应用程序服务器。 我想设置一些标题,如X-XSS-Protection或Strict-Transport-Security 。 目前,它在应用程序服务器和负载平衡器上都被设置,这导致标题变得复杂。 Error parsing header X-XSS-Protection: 1; mode=block, 1; mode=block: expected semicolon at character position 14. The default protections will be applied. 我可以看到重复的标题值被附加到相同的标题关键字。 我的问题是:设置标题的一般惯例/最佳做法是什么? 我应该在后端设置标题并将它们从负载平衡器中移除,或者负载平衡器应该是一个设置标题?

在AWS ELB上强制使用HTTPS

我使用自定义域在AWS ELB上托pipe了一个基于Java的,基于JAR的小型Web应用程序。 我上传一个ZIP文件,如: myapp.zip * myapp.jar 我使用AWS CMconfiguration了一个证书,并能够通过http://www.example.com和https://www.example.com访问我的应用程序。 现在我需要总是 强制使用 HTTPS。 我完全失去了如何做到这一点。 我看到了许多答案,如“configuration你的nginx”: https://stackoverflow.com/questions/24603620/redirecting-ec2-elb-from-http-to-https https://aws.amazon.com/de/premiumsupport/knowledge-center/redirect-http-https-elb / http://www.emind.co/how-to/how-to-force-https-behind-aws-elb/ 其他答案都是一致的。 虽然我可以理解重写规则的想法,例如: if ($http_x_forwarded_proto = 'http') { return 301 https://www.example.com$request_uri; } 我所缺less的是如何实际添加这个AWS ELB nginx。 我上次尝试的是将.ebextensions\nginx\conf.d\my.conf到我的ZIP压缩文件中: myapp.zip * myapp.jar * .ebextensions * nginx * conf.d * my.conf 内容: if ($http_x_forwarded_proto = 'http') { return 301 https://www.example.com$request_uri; } 这给了我以下错误: 2016/12/24 […]

我有nginx的多个实例,但不知道哪一个是“正确的”

我inheritance了一个生产Web服务器,并且我看到至less5个nginx的副本: /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old /usr/local/nginx-new/sbin/nginx /usr/local/nginx-nobrotli/sbin/nginx /usr/sbin/nginx 当使用“-v”选项运行时,前4个返回“nginx版本:nginx / 1.10.0”,而最后一个返回“nginx版本:nginx / 1.0.15”。 服务器正在提供实时stream量,所以我必须非常小心地做出任何更改。 从运行ps aux | grep nginx ps aux | grep nginx我可以看到,目前正在使用的是nginx-nobrotli : nginx: master process /usr/local/nginx-nobrotli/sbin/nginx -c /etc/nginx/nginx.conf 让我困惑的是,当我从命令行键入nginx -t ,我得到错误。 我认为这是因为我真的调用/usr/sbin/nginx -t (因为nginx -v给出了“nginx版本:nginx / 1.0.15”我认为这是调用第五个)。 所以这里是真正的问题: 我怎么才能重新启动nginx,并确保它使用相同的configuration,目前正在运行? (我吓坏了,如果我做了一个nginx -s reload它会通过加载错误版本的nginx来取消网站) 使nginx -t命令的最佳方式是指nginx -t的“正确”版本? (假设当前运行的是正确的) 在/etc/nginx/conf.d/看到的configuration文件与我在/usr/local/nginx*/conf/文件夹中看到的configuration文件有什么区别? 如果/usr/local/nginx*文件夹在它们各自的sbin/文件夹下都包含一个二进制文件,这是否意味着它们是相同的? 为什么有人会有这样的3个版本? 更新1: 命令nginx -t返回这个: nginx: [emerg] […]

LetsEncrypt不想validation我的域名

这在过去的几天里一直在困扰着我,我似乎无法弄清楚发生了什么事情。 我有一个新的服务器我安装(使用灶神星 ,与Nginx)。 他们有一个使用LetsEncrypt的内置工具,据说这已经奏效了: …然后正在编辑的域名: snginx.conf文件具有(和那些文件确实存在)中的设置: ssl_certificate /home/admin/conf/web/ssl.steampj.com.pem; ssl_certificate_key /home/admin/conf/web/ssl.steampj.com.key; 定义server {时我也有这个server { bit: server { listen 443 ssl; listen [::]:443 ssl; 重新启动/重新加载nginx时,我没有得到任何错误。 你当你走到这里,你会得到一个错误: https : //steampj.com/ 和: 我很困惑,为什么它不工作 以下是该域的完整server {}条件: server { listen 443 ssl; listen [::]:443 ssl; server_name steampj.com www.steampj.com; root /home/admin/web/steampj.com/public_html; index index.php index.html index.htm; access_log /var/log/nginx/domains/steampj.com.log combined; access_log /var/log/nginx/domains/steampj.com.bytes bytes; error_log […]

Terse NGINXconfiguration许多几乎相同的站点

我有一个NGINXnetworking服务器,我主持了许多小型网站。 每个网站都有一个唯一的域名(有或没有子域),一个HTML文件和一个PHP文件,并具有相同的configuration。 每个网站的唯一区别是: 域名 – example.com 一些简单的HTML – <title>Example Site</title> 服务器上的文件path – /usr/share/nginx/example.com/html 到目前为止,我一直在为每个网站添加一个服务器块文件,这一直很好。 但是,这个过程是乏味的,我复制了大量的样板configuration。 我在服务器上获取的网站越来越多,这个过程也不像我想的那样具有可扩展性。 由于一切都如此相似,我希望能够定义一次configuration,而不必再担心它。 有没有一种简单的方法来configuration多个网站,从不同的子文件夹提供服务? EG我将把Nginx指向/usr/share/nginx/ ,它将自动根据HTTP请求中的example.com域selectexample.com子文件夹。

NGINX忽略服务器块中的上游

这是我的/etc/nginx/nginx.conf文件的样子(按照nginx -T ): # configuration file /etc/nginx/nginx.conf: # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { log_format main '$remote_addr – $remote_user [$time_local] […]