我的WordPress的应用程序运行在https://example.com/wordpress/myapp 。 我已经设置nginx像这样:
#user nobody; worker_processes 1; error_log /var/log/nginx/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { #allows file uploads up to 8 megabytes client_max_body_size 50M; server_tokens off; include mime.types; default_type application/octet-stream; log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_header_buffer_size 4k; large_client_header_buffers 4 16k; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Websocket support #upstream websocket { # server 127.0.0.1:<PORT>; #} server { listen 80; server_name localhost; #cookies default descomplica client_header_buffer_size 4k; large_client_header_buffers 4 16k; #charset koi8-r; #access_log logs/host.access.log main; include /etc/nginx/aliases.conf; #location /ws { # proxy_pass http://websocket; # proxy_http_version 1.1; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "Upgrade"; #} location /wordpress/myapp { root /var/www/webroot; index index.php /wordpress/index.php; try_files $uri $uri/ /wordpress/index.php?$args; location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param PATH_INFO $fastcgi_script_name; } } index index.php index.html index.htm; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} location ~ /\. { deny all; access_log off; log_not_found off; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} location ~ \.php$ { location ~ /\. { deny all; access_log off; log_not_found off; } include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/webroot; } } include /etc/nginx/conf.d/*.conf; }
我的项目根在:
/var/www/webroot/wordpress
我可以访问应用程序,并浏览所有链接,但没有图像,JavaScript和样式表加载。 他们都返回Wordpress的未find的页面,就像是一个PHP页面,而不是一个静态文件。
error.log中
2017/08/11 00:54:20 [error] 8085#0:* 290在stderr中发送FastCGI:“无法打开主脚本:/var/www/webroot/wordpress/myapp/wp-cron.php文件或目录)“,而从上游读取响应头,客户端:10.70.28.156,服务器:本地主机,请求:”POST /wordpress/myapp/wp-cron.php?doing_wp_cron=1502412860.0307459831237792968750 HTTP / 1.1“,上游:”fastcgi: //127.0.0.1:9000“,主持人:”gabaquest.jelasticlw.com.br“,推荐人:” http://example.com/wordpress/myapp/wp-cron.php?doing_wp_cron=1502412860.0307459831237792968750 “
PHP-fpm.log
[11-Aug-2017 00:51:59]警告:[池www]子8075说成stderr:“错误:无法打开主脚本:/var/www/webroot/wordpress/myapp/wp-cron.php没有这样的文件或目录)“[11-Aug-2017 00:52:17]警告:[池www]子8082说成stderr:”错误:无法打开主脚本:/var/www/webroot/xmlrpc.php (没有这样的文件或目录)“[11-Aug-2017 00:52:17]警告:[池www]子8083说成stderr:”错误:无法打开主脚本:/ var / www / webroot / wp- login.php(没有这样的文件或目录)“[11-Aug-2017 00:52:18]警告:[池www]子8033说成stderr:”错误:无法打开主脚本:/ var / www / webroot /wp-login.php(没有这样的文件或目录)“[11-Aug-2017 00:52:18]警告:[池www]子8035说成stderr:”错误:无法打开主脚本:/ var / www / webroot / wp-login.php(没有这样的文件或目录)“[11-Aug-2017 00:52:18]警告:[池www]子8034说成stderr:”错误:无法打开主脚本:在/ var / WWW / Webroot公司/可湿性粉剂login。 PHP的(没有这样的文件或目录)“[11-Aug-2017 00:54:20]警告:[池www]子8037说成stderr:”错误:无法打开主脚本:/ var / www / webroot / wordpress /myapp/wp-cron.php(没有这样的文件或目录)“
php_errors.log
[11-Aug-2017 00:52:17 UTC] PHP已弃用:自动填充$ HTTP_RAW_POST_DATA已弃用,将在未来版本中删除。 为避免此警告,在php.ini中将“always_populate_raw_post_data”设置为“-1”,并改为使用php://inputstream。 在第0行的未知
它看起来像你已经打破了configuration相当一点,试图解决它。 我已经尽力将其恢复到工作状态。
将来,请确保在正常的非正则expression式块的末尾有一个斜线。 Nginx指令对尾随斜线敏感; 只需添加或删除一个斜杠即可完全改变指令的行为。
从技术上讲,处理这种情况的正确方法是使用别名指令 ,但是它与一些stream行的Nginx特性(包括fastcgi模块)结合在一起非常麻烦。 相反,我采取了重写路线。 这不会导致redirect; 重写是内部的。
#user nobody; worker_processes 1; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/notice.log notice; #error_log /var/log/nginx/info.log info; events { worker_connections 1024; } http { #allows file uploads up to 50 megabytes client_max_body_size 50M; server_tokens off; include mime.types; default_type application/octet-stream; log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; client_header_buffer_size 4k; large_client_header_buffers 4 16k; sendfile on; #tcp_nopush on; keepalive_timeout 65; server { listen 80; server_name localhost; root /var/www/webroot; index index.php index.html index.htm; #cookies default descomplica client_header_buffer_size 4k; large_client_header_buffers 4 16k; #charset koi8-r; # TODO: This may need to be removed. This could be part of the problem. include /etc/nginx/aliases.conf; location ~ /\. { return 404; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param PATH_INFO $fastcgi_script_name; } location ^~ /wordpress/myapp/ { # We could use the `alias` directive instead, but that tends to break in combination with the fastcgi module. rewrite ^/wordpress/myapp(/.*)$ $1; } location /wordpress/ { # If you want to prevent people from visiting /wordpress/ directly and require that they visit /wordpress/myapp/, you can try uncommenting the next line. You'll also need to duplicate the PHP location block, change the regex in the new one to `^/wordpress/.*\.php$`, and add the `internal` directive to that, too. #internal; try_files $uri $uri/ /wordpress/index.php; # This PHP file has to come last. It's deliberately missing `myapp`. } location / { try_files $uri $uri/ =404; } # TODO: This either needs to be `location = /ws` or `location ^~ /ws/`. Note the trailing slash. #location /ws { # proxy_pass http://websocket; # proxy_http_version 1.1; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "Upgrade"; #} } include /etc/nginx/conf.d/*.conf; }