PHP 应用程序部署 Ubuntu 16.04 nginx apache 设置



我已经是第三天了,我正在尝试部署一个小的php应用程序。 我们将我们的应用程序(即 3 个轨道应用程序和 1 个 php(移动到同一服务器。 Rails 应用程序工作正常。PHP没有。 我从来没有真正部署过PHP应用程序,所以我是通过指南来做的。到目前为止,我得到了这种情况: 如果我尝试在浏览器中打开PHP应用程序,我会看到默认的Apache页面。如果我刷新页面,它将显示索引.php文件的内容,但显示为空白文本。再次刷新 - 默认的 Apache 页面,再次刷新 - 索引.php的内容。

我的设置:

nginx/sites-available/my.site(在 sites-enabled 中启用(

server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/my.site/httpdocs;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name my.site www.my.site;
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
}
location ~* .(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires      30d;
}
location @proxy {
proxy_pass http://127.0.0.1:8000;
include /etc/nginx/proxy_params;
}
location ~* .php$ {
proxy_pass http://127.0.0.1:8000;
include /etc/nginx/proxy_params;
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
}

apache2/sites-available/my.site

ServerName my.site
ServerAlias www.my.site
ServerAdmin webmaster@localhost
DocumentRoot /var/www/my.site/httpdocs
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

apache2/ports.conf

NameVirtualHost 127.0.0.1:8000
Listen 8000
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>

在休息日工作时,不知道如何修复服务器。任何建议不胜感激。

> nginx config

map $sent_http_content_type $expires {
default               off;
~css                  max;
~javascript       max;
~image             max;
~font-woff        max;
~video               max;
~zip                   max;
~txt                    max;
}
expires                 $expires;
server {
listen 80;
server_name exemple.com;
root /home/to/exemple.com;
index index.php index.html;             
gzip                    on;
gzip_min_length         128;
gzip_http_version       1.1;
gzip_buffers           128 32k;
gzip_types
text/css
text/javascript
text/xml
text/plain
text/x-component
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
application/atom+xml
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_static  on;    
gzip_proxied            expired no-cache no-store private auth;
gzip_disable            "msie6";
gzip_vary                on;
location / {
proxy_pass http://127.0.0.1:8000;
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;
}
}

Apache 配置

PHP 7 mod

apt install libapache2-mod-php7.0

PHP5 模组

apt install libapache2-mod-php

包括例如 php7.0 mod

a2enmod php7.0

VirtualHost config apache

<VirtualHost *:8000>
ServerName exemple.com
DocumentRoot /home/to/exemple.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
<Directory /home/to/exemple.com/>
php_admin_flag engine on
Options -ExecCGI -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

在 apache2.conf 中删除NameVirtualHost 127.0.0.1:8000粘贴服务器名称 127.0.0.1

systemctl restart apache2
systemctl restart nginx

原始帖子 apache2+nginx 代理

最新更新