【发布时间】:2019-12-29 18:49:05
【问题描述】:
我想知道如何在 Nginx 上拥有多个站点并能够使用相同的 IP 访问每个站点(没有域,因为我在本地实验室进行测试)。
我在单独的 PC 上拥有服务器,我使用 IP 从我的计算机远程访问它。两者都在同一个局域网上。
在目录 /var/www/ 我有两个站点“nextcloud”和“phpmyadmin”。我希望能够通过放置(例如)192.168.1.14/nextcloud 和 192.168.1.14/phpmyadmin 来输入两者。或者在 www 目录中有任何其他项目。
我尝试了所有找到的解决方案,但没有一个对我有用。例如,当我输入 phpmyadmin 时,它让我下载页面而不是输入它。
在 /etc/nginx/sites-enabled 我有两个文件,一个来自 nextcloud:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/nextcloud/;
index index.php index.html index.htm;
server_name localhost;
client_max_body_size 512M;
fastcgi_buffers 64 4K;
location / {
root /var/www/nextcloud;
rewrite ^ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
还有 phpmyadmin 的:
server {
listen 80;
listen [::]:80;
root /var/www/phpmyadmin/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
尝试在 /var/www/ 中创建两个测试文件夹(test1 和 test2),每个文件夹里面都有一个 index.html 文件并修改 nginx 默认文件,但它对我也不起作用
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
index index.html;
location / {
return 410; # Default root of site won't exist.
}
location /test1/ {
alias /var/www/test1/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
location /test2/ {
alias /var/www/test2/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
}
正如我所说,我尝试了不同的解决方案。我遇到的另一个问题是它只将我重定向到 nextcloud,尽管我将 phpmyadmin 放在了 url 中。和上一个我已经提到的,当我进入时,下载index.php。谢谢。
对不起我的英语。
【问题讨论】:
标签: php nginx phpmyadmin